Reprinted from: https://blog.csdn.net/bxzhu/article/details/73253032
1. Environmental preparation
Linux version: Centos7
docker version: 17.05.0-ce
2. Deploy the Registry
Use the docker pull command to get the image of the registry
- # sudo docker pull registry:2.1.1
Use docker run to start a container with the downloaded registry image
- # sudo docker run -d -p 5000:5000 -v /opt/registry:/var/lib/registry --restart=always --name registry registry:2.1.1
View launched containers
- # sudo docker ps
- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- ebb16548e9d3 registry:2.1.1 "/bin/registry /et..." 12 seconds ago Up 11 seconds 0.0.0.0:5000->5000/tcp registry
Open the browser and visit http://IP:5000/v2/_catalog, you can see that {"repositories": []} means that there are no mirror images in the warehouse now
Now, download an image and upload it to the local repository. The following takes the busybox image as an example
- # sudo docker pull busybox
- Using default tag: latest
- latest: Pulling from library/busybox
- 27144aa8f1b9: Pull complete
- Digest: sha256:be3c11fdba7cfe299214e46edc642e09514dbb9bbefcd0d3836c05a1e0cd0642
- Status: Downloaded newer image for busybox:latest
- # sudo docker images
- REPOSITORY TAG IMAGE ID CREATED SIZE
- busybox latest c30178c5239f Less than a second ago 1.11 MB
- hello-world latest 1815c82652c0 20 hours ago 1.84 kB
- registry 2.1.1 52bb991b482e 20 months ago 220 MB
- # sudo docker tag busybox 192.168.61.128:5000/busybox
- # sudo docker images
- REPOSITORY TAG IMAGE ID CREATED SIZE
- 192.168.61.128:5000/busybox latest c30178c5239f Less than a second ago 1.11 MB
- busybox latest c30178c5239f Less than a second ago 1.11 MB
- hello-world latest 1815c82652c0 20 hours ago 1.84 kB
- registry 2.1.1 52bb991b482e 20 months ago 220 MB
- # sudo docker push 192.168.61.128:5000/busybox
- The push refers to a repository [192.168.61.128:5000/busybox]
- Get https://192.168.61.128:5000/v1/_ping: http: server gave HTTP response to HTTPS client
解决方式,可以参考一下方式
修改文件/usr/lib/systemd/system/docker.service,在ExecStart=/usr/bin/dockerd后面添加--insecure-registry 192.168.61.128:5000,然后重启docker服务
- # cat /usr/lib/systemd/system/docker.service
- [Unit]
- Description=Docker Application Container Engine
- Documentation=https://docs.docker.com
- After=network.target firewalld.service
- [Service]
- Type=notify
- # the default is not to use systemd for cgroups because the delegate issues still
- # exists and systemd currently does not support the cgroup feature set required
- # for containers run by docker
- ExecStart=/usr/bin/dockerd --insecure-registry 192.168.61.128:5000
- ExecReload=/bin/kill -s HUP $MAINPID
- # Having non-zero Limit*s causes performance problems due to accounting overhead
- # in the kernel. We recommend using cgroups to do container-local accounting.
- LimitNOFILE=infinity
- LimitNPROC=infinity
- LimitCORE=infinity
- # Uncomment TasksMax if your systemd version supports it.
- # Only systemd 226 and above support this version.
- #TasksMax=infinity
- TimeoutStartSec=0
- # set delegate yes so that systemd does not reset the cgroups of docker containers
- Delegate=yes
- # kill only the docker process, not all processes in the cgroup
- KillMode=process
- [Install]
- WantedBy=multi-user.target
- # sudo systemctl daemon-reload && sudo systemctl restart docker.service
- # sudo docker push 192.168.61.128:5000/busybox
- The push refers to a repository [192.168.61.128:5000/busybox]
- 3a1dff9afffd: Pushed
- latest: digest: sha256:417ae70baa235876876e723f4b630afa7f91a113025d70361597656b5cf0481b size: 2136
Open the browser, visit http://IP:5000/v2/_catalog, you can see that {"repositories": ["busybox"]} means that there is a mirror busybox in the warehouse now