Docker Registry Local Mirror
Why I needed it
I recently started working on some personal projects to do and learn things that I had in my TODO list for a very long time.
One of the moments when I work on them is during my (long) commuting times when I go to the office or somewhere else by train.
In order to get my docker images I need internet connection provided by my phone and it brings a couple of problems:
- I don't have a large amount of GB per month so I am exhausting my available data pretty soon.
- When I am in tunnels, etc. the connection is dropped.
When docker images are new, there is no way to escape it, but I usually use the same docker images for the same projects. Once they
are downloaded there is no problem but I like keeping the amount of images in my system under control, so I want to be able to do:
docker rmi -f $(docker images -aq)
often.
I thought that it would be cool to have a mirror of the docker registry with the images I use so I can keep running this command and pull the images
from my computer.
That's why I decided to try out and add a docker registry mirror on my machine. And it turned out much easier than I expected.
How it works
The docker daemon is configured to pull through the mirror, and the mirror keeps every image it serves on local disk:
- Online, first pull: the mirror does not have the image, so it pulls it from Docker Hub, stores it and returns it.
- Offline, image already pulled: the mirror returns its stored copy and Docker Hub is never contacted.
- Offline, image never pulled: the mirror cannot reach Docker Hub, so the pull fails.
How can you use it
The code and the explanation on how to use it can be found in the docker-registry-mirror repository.
Happy (and low data usage) programming!