1. 环境准备
Linux版本:Centos7
docker版本:17.05.0-ce
2. 部署Registry
使用docker pull命令获取registry的image

[plain]
​​view plain​​​
​​​copy​​



1. # sudo docker pull registry:2.1.1
使用docker run使用下载的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
查看启动的容器

[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
打开浏览器,访问http://IP:5000/v2/_catalog,可以查看到{"repositories": []}表示现在仓库中,没有镜像images
现在,下载一个镜像,然后传到本地仓库中,以下以busybox镜像为例

[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
在本地host上面,给busybox添加新的tag

[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
打开浏览器,访问http://IP:5000/v2/_catalog,可以查看到{"repositories": ["busybox"]}表示现在仓库中,存在镜像busybox这一个