If you are behind a proxy and want to proxy docker registry or have multiple machines pulling the same images over and over (CI/CD/ML/DL etc..) and just want to cache them locally the following is a good choice.
create a folder docker-registry-local-cache
and create docker-compose.yml
file as follows and customize it with your env variables.
vi docker-compose.yml
version: "2"
services:
registry2:
image: registry:2
ports:
- 5000:5000
environment:
- REGISTRY_PROXY_REMOTEURL="https://registry-1.docker.io"
- HTTP_PROXY=example.com:80
- HTTPS_PROXY=example.com:80
- NO_PROXY="localhost,127.0.0.1,10.0.0.7"
- no_proxy="localhost,127.0.0.1,10.0.0.7"
volumes:
- /opt/registry:/var/lib/registry
run the container with
docker-compose up -d
run
docker logs dockerregistrylocalcache_registry2_1
and you should see the following
time="2018-04-04T23:18:28Z" level=info msg="Registry configured as a proxy cache to https://registry-1.docker.io" go.version=go1.7.6 instance.id=76e861f3-cd4c-463e-880f-847d152cb565 version=v2.6.2
time="2018-04-04T23:18:28Z" level=info msg="listening on [::]:5000" go.version=go1.7.6 instance.id=76e861f3-cd4c-463e-880f-847d152cb565 version=v2.6.2
run
curl http://10.0.0.7:5000/v2/_catalog
should output in something similar to this
{"repositories":[]}
Next configure your docker client to use this mirror. See this previous post on how to do that.
Once client side is configured, you can pull a image from a remote dockerhub via your local mirror. For example run
docker pull ubuntu:17.10
like you normally would. then run
curl http://10.0.0.7:5000/v2/_catalog"
again to see the following
{"repositories":["library/ubuntu"]}
This should significantly improve the speed of any subsequent pull from the local clients. Hope you finds this useful.
Leave a Reply