Twelve ) Build local Registry
Docker Hub Although very convenient , But there are limits , such as :
- need internet Connect , And it's slow to download and upload .
- Upload to Docker Hub Is accessible to anyone , Although you can use private repository, But it's not free .
- Many organizations do not allow images to be placed on the extranet for security reasons .
The solution is to build locally Registry.Docker Have already put Registry Open source , At the same time Docker Hub There is also an official mirror image registry. And down here we are Docker Runs its own registry.
(1) Private warehouse configuration :
Increase trust :
root@cuiyongchao:/dockerfile# cat /etc/docker/daemon.json
{ "insecure-registries":["10.0.0.20:5000"] }
root@cuiyongchao:/dockerfile#
Turn on https:
cat /lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd --insecure-registry 10.0.0.20:5000
Restart after modification docker service
systemctl daemon-reload
systemctl restart docker
restart docker After service , Restart the container
docker start $(docker ps -aq)
(2) Create a container
① start-up registry Containers .
root@cuiyongchao:/dockerfile# docker run -d -p 5000:5000 -v /myregistry:/var/lib/registry registry:2
Unable to find image 'registry:2' locally
2: Pulling from library/registry
cbdbe7a5bc2a: Pull complete
47112e65547d: Pull complete
46bcb632e506: Pull complete
c1cc712bcecd: Pull complete
3db6272dcbfa: Pull complete
Digest: sha256:8be26f81ffea54106bae012c6f349df70f4d5e7e2ec01b143c46e2c03b9e551d
Status: Downloaded newer image for registry:2
23db09da07b88129b557ebd1c3e960e700bca8d88c39a0ca01d2db05532671f1
root@cuiyongchao:/dockerfile#
notes :
① The mirror is registry:2.
②`-d` Is the background startup container .
③`-p` The container of 5000 Port maps to Host Of 5000 port .5000 yes registry Service port . Port mapping is discussed in detail in the container network chapter .
④`-v` The container /var/lib/registry Directory maps to Host Of /myregistry, Used to hold mirror data .`-v` We will discuss in detail in the container storage section .
② adopt docker tag
Rename mirror , To that of the registry matching .
docker tag cuiyongchao007/httpd:v1 10.0.0.20:5000/cuiyongchao007/httpd:v1
We put a run in front of the mirror registry Host name and port . We have already discussed the image name by repository and tag Two parts . and repository The full format is :[registry-host]:[port]/[username]/xxx Only Docker Hub The mirror image on can be omitted [registry-host]:[port] .
③ adopt docker pull
Upload the image .
root@cuiyongchao:/dockerfile# docker push 10.0.0.20:5000/cuiyongchao007/httpd
The push refers to repository [10.0.0.20:5000/cuiyongchao007/httpd]
850c0c904ff3: Pushed
c264370aa736: Pushed
e6f7f192bbc8: Pushed
6d80bc0bd923: Pushed
d0fe97fa8b8c: Pushed
v1: digest: sha256:60b82a0c2599b217d5231d3a54eb9f691ac8bc15b66f8f5f79f383f87c9c51ce size: 1366
④ It is now available through docker pull
From local registry Download mirroring
root@cuiyongchao:/dockerfile# docker pull 10.0.0.20:5000/cuiyongchao007/httpd:v1
v1: Pulling from cuiyongchao007/httpd
Digest: sha256:60b82a0c2599b217d5231d3a54eb9f691ac8bc15b66f8f5f79f383f87c9c51ce
Status: Downloaded newer image for 10.0.0.20:5000/cuiyongchao007/httpd:v1
10.0.0.20:5000/cuiyongchao007/httpd:v1
The above is to build local registry A brief step of . Of course registry It also supports authentication ,https Secure transmission and other features , Please refer to official documents for details https://docs.docker.com/registry/configuration/