Wednesday, 27 February 2019

Installing a Docker Registry Cache on your Raspberry Pi



In this example - our local Raspberry Pi has the IP address 192.168.1.194

On your Pi – First install ‘Go version 1.8’ -

cd ~

tar -C /usr/local -xzf go1.8.linux-armv6l.tar.gz

export PATH=$PATH:/usr/local/go/bin

Now Clone, build and install the Docker Registry project

git clone https://github.com/docker/distribution.git

cd distribution

go get ./...


GOOS=linux GOARCH=arm make binaries

After making the binaries – you should issue the command

ls bin/

and you should see files: digest, registry, registryapidescriptortemplate


Before running the service you need to set up a config file to tell the registry service where to put images and to tell it to behave as a proxy for the main Docker repos images (nginx:latest, httpd:alpine etc) .

Create ~/distribution/bin/registry-config.yml and copy the following content into it:

version: 0.1
storage:
  cache:
    blobdescriptor: inmemory
  filesystem:
    rootdirectory: /var/lib/registry
http:
  addr: :5000
proxy:
 remoteurl: https://registry-1.docker.io


Create ~/distribution/bin/registry-config.yml and copy the following content into it:
Finally make a directory to store the images on your Pi

sudo mkdir p /var/lib/registry
sudo chown $USER /var/lib/registry


Finally start up your Registry Server.

cd ~/distribution/bin/
./registry serve ~/registryconfig.yml




On your Desktop/Laptop (Docker Client)



Under the Docker Preferences setup your PI server as a
‘Registry Mirror’




Apply and Restart your Docker Application



Testing


On your Docker client desktop/laptop – open up a browser and after making sure you’re on the same subnet as your Pi – go to the location
http://192.168.1.194:5000/v2


You should notice the empty ‘{ }’ JSON response on your browser.





If you have a shell open where your Pi is running the service – you’ll notice the response.




Now let’s pull some images from the main Docker Repo.

Using a terminal – on your Client machine (Desktop or Laptop)

Issue the following commands

docker image rm hello-world  

Don’t worry if you get an error on this command.

docker image pull hello-world


When the client starts to pull the image – you should notice DEBUG information on your Pi terminal – indicating that the image is being cached on its system.


After the ‘pull’ command has  been completed – issue another ‘rm command’

docker image rm hello-world  

And then another ‘pull’
docker image pull hello-world


On the Pi console – you will notice that the image is now being pulled from the local Pi directory rather than over the internet.


On your Docker Client machine (Desktop/Laptop) – issue the _catalog service on the browser (http://192.168.1.194:5000/v2/_catalog)

You should notice – a list of cached images stored on the Pi.

 


 Finally


On your Pi - you may want to bind mount /var/library/registry on a USB drive

sudo mount /dev/sda1 /var/lib/registry/ -o umask=000    

#sudo umount /var/lib/registry/





No comments:

Post a Comment