Docker Registry – Hub Mirror and Local Private
About
This is a simple Docker Compose system that lets one run 2 Docker Registries on the same system:
- A Registry acting as a mirror for the Docker Hub
- A Registry for private images, meant for local development and sharing between Docker hosts (including localhost as well as Docker Machines and Minikube)
How to use
Launch this just like any Compose system:
docker-compose up -d
Then, update your Docker host’s dockerd
configuration to run with the
--registry-mirror
and --insecure-registry
options. For example, on
systems using /etc/default/docker
for configuration:
# on systems using /etc/default/docker
DOCKER_OPTS="--registry-mirror=http://127.0.0.1:50000 --insecure-registry=192.168.42.1:50001"
And for systems using /etc/docker/daemon.json
:
{
"insecure-registries": ["192.168.42.1:50001"],
"registry-mirrors": ["http://127.0.0.1:50000"]
}
The containers are configured to always restart, so one just needs to do this initial setup once, and it will retain across Docker host reboots.
Tips & Tricks
Using the same Registries across Docker Machines
My reference setup is a 6-node Docker Machine setup that I will
configure into a Docker Swarm later. Since I’m using a libvirt/KVM
setup where my main Docker Engine is on 192.168.122.1
, I can set up
my VMs like this:
for m in swarm-{manager,worker}-{1,2,3}; do
docker-machine create ... \
--engine-registry-mirror=http://192.168.122.1:50000 \
--engine-insecure-registry http://192.168.122.1:50001 $m
done
Using external directories for registry volumes
If you wish to use your host’s directory for storing registry data instead of letting Compose make a named volume for you, just change the volumes settings of the registry containers. For example:
services:
registry_mirror:
...
volumes:
- /my/mirror/directory:/var/lib/registry
See Also
- Zakame::Blog - Composinga Docker Hub Mirror and Private Registry
- Zakame::Blog - Mirroring the Docker Hub
License
The MIT License (MIT)
Copyright (C) Zak B. Elep.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.