Local construction of docker private warehouse registry

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

[plain]  view plain copy  
  1. # sudo docker pull registry:2.1.1  

Use docker run to start a container with the downloaded registry image

[plain]  view plain copy  
  1. # sudo docker run -d -p 5000:5000 -v /opt/registry:/var/lib/registry --restart=always --name registry registry:2.1.1  

View launched containers

[plain]  view plain copy  
  1. # sudo docker ps  
  2. CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES  
  3. 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

[plain]  view plain copy  
  1. # sudo docker pull busybox  
  2. Using default tag: latest  
  3. latest: Pulling from library/busybox  
  4. 27144aa8f1b9: Pull complete   
  5. Digest: sha256:be3c11fdba7cfe299214e46edc642e09514dbb9bbefcd0d3836c05a1e0cd0642  
  6. Status: Downloaded newer image for busybox:latest  
  7. # sudo docker images  
  8. REPOSITORY          TAG                 IMAGE ID            CREATED                  SIZE  
  9. busybox             latest              c30178c5239f        Less than a second ago   1.11 MB  
  10. hello-world         latest              1815c82652c0        20 hours ago             1.84 kB  
  11. registry            2.1.1               52bb991b482e        20 months ago            220 MB  
On the local host, add a new tag to busybox

[plain]  view plain copy  
  1. # sudo docker tag busybox 192.168.61.128:5000/busybox  
  2. # sudo docker images  
  3. REPOSITORY                    TAG                 IMAGE ID            CREATED                  SIZE  
  4. 192.168.61.128:5000/busybox   latest              c30178c5239f        Less than a second ago   1.11 MB  
  5. busybox                       latest              c30178c5239f        Less than a second ago   1.11 MB  
  6. hello-world                   latest              1815c82652c0        20 hours ago             1.84 kB  
  7. registry                      2.1.1               52bb991b482e        20 months ago            220 MB   
将镜像上传到仓库中

[plain]  view plain  copy
  1. # sudo docker push 192.168.61.128:5000/busybox  
  2. The push refers to a repository [192.168.61.128:5000/busybox]  
  3. Get https://192.168.61.128:5000/v1/_ping: http: server gave HTTP response to HTTPS client   
出现上述提示,表示本地的仓库默认使用的是https进行上传,如果是非https就会出现以上的提示

解决方式,可以参考一下方式

修改文件/usr/lib/systemd/system/docker.service,在ExecStart=/usr/bin/dockerd后面添加--insecure-registry 192.168.61.128:5000,然后重启docker服务

[plain]  view plain  copy
  1. # cat /usr/lib/systemd/system/docker.service  
  2. [Unit]  
  3. Description=Docker Application Container Engine  
  4. Documentation=https://docs.docker.com  
  5. After=network.target firewalld.service  
  6.   
  7. [Service]  
  8. Type=notify  
  9. # the default is not to use systemd for cgroups because the delegate issues still  
  10. # exists and systemd currently does not support the cgroup feature set required  
  11. # for containers run by docker  
  12. ExecStart=/usr/bin/dockerd --insecure-registry 192.168.61.128:5000  
  13. ExecReload=/bin/kill -s HUP $MAINPID  
  14. # Having non-zero Limit*s causes performance problems due to accounting overhead  
  15. # in the kernel. We recommend using cgroups to do container-local accounting.  
  16. LimitNOFILE=infinity  
  17. LimitNPROC=infinity  
  18. LimitCORE=infinity  
  19. # Uncomment TasksMax if your systemd version supports it.  
  20. # Only systemd 226 and above support this version.  
  21. #TasksMax=infinity  
  22. TimeoutStartSec=0  
  23. # set delegate yes so that systemd does not reset the cgroups of docker containers  
  24. Delegate=yes  
  25. # kill only the docker process, not all processes in the cgroup  
  26. KillMode=process  
  27.   
  28. [Install]  
  29. WantedBy=multi-user.target  
  30. # sudo systemctl daemon-reload && sudo systemctl restart docker.service  
重新上传

[plain]  view plain  copy
  1. # sudo docker push 192.168.61.128:5000/busybox  
  2. The push refers to a repository [192.168.61.128:5000/busybox]  
  3. 3a1dff9afffd: Pushed   
  4. 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


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326262165&siteId=291194637