Docker配置2.x私有仓库

宿主服务器IP:172.21.28.161


1.下载registry镜像

sudo docker pull hub.c.163.com/library/registry:latest

2.启动registry镜像

sudo docker run -d -v /docker/registry/v2:/var/lib/registry -p 5000:5000 --restart=always --name registry_v2 registry:latest
registry仓库默认把待上传的镜像放到/var/lib/registry,把宿主目录/docker/registry/v2关联到仓库上传目录中

3.对待上传的镜像打tag

[appadmin@CentOS]$ <span style="color:#FF0000;">sudo docker images</span>
REPOSITORY                       TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
hub.c.163.com/library/registry   latest              71adeb46c789        2 weeks ago         33.27 MB
hub.c.163.com/library/centos     6.7                 a8b4df3be85c        4 weeks ago         190.6 MB
<pre name="code" class="plain">[appadmin@CentOS]
[appadmin@CentOS]$ sudo docker tag hub.c.163.com/library/centos:6.7 172.21.28.161:5000/centos:6.7
[appadmin@CentOS]
[appadmin@CentOS]$ sudo docker images
REPOSITORY                       TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
hub.c.163.com/library/registry   latest              71adeb46c789        2 weeks ago         33.27 MB
172.21.28.161:5000/centos        6.7                 a8b4df3be85c        4 weeks ago         190.6 MB
hub.c.163.com/library/centos     6.7                 a8b4df3be85c        4 weeks ago         190.6 MB
[appadmin@CentOS v2]
 4.上传镜像172.21.28.161:5000/centos:6.7,发现报错 

[appadmin@CentOS]$ <span style="color:#FF0000;">sudo docker push 172.21.28.161:5000/centos:6.7</span>
Error response from daemon: invalid registry endpoint https://172.21.28.161:5000/v0/: unable to ping registry endpoint https://172.21.28.161:5000/v0/
v2 ping attempt failed with error: Get https://172.21.28.161:5000/v2/: tls: oversized record received with length 20527
 v1 ping attempt failed with error: Get https://172.21.28.161:5000/v1/_ping: tls: oversized record received with length 20527. If this private registry supports only HTTP or HTTPS with an unknown CA certificate, please add `--insecure-registry 172.21.28.161:5000` to the daemon's arguments. In the case of HTTPS, if you have access to the registry's CA certificate, no need for the flag; simply place the CA certificate at /etc/docker/certs.d/172.21.28.161:5000/ca.crt
[appadmin@CentOS]$

修改/etc/sysconfig/docker,把

#other_args=
改为
other_args="--insecure-registry 172.21.28.161:5000"

5.重启docker服务

[appadmin@CentOS]$ <span style="color:#FF0000;">sudo service docker restart</span>

6.再次上传镜像172.21.28.161:5000/centos:6.7,成功

[appadmin@CentOS]$ <span style="color:#FF0000;">sudo docker push 172.21.28.161:5000/centos:6.7</span>
The push refers to a repository [172.21.28.161:5000/centos] (len: 1)
a8b4df3be85c: Image already exists 
2352e8cfa843: Image already exists 
505dff91e9c8: Image already exists 
3624df1f7cf0: Image successfully pushed 
3690474eb5b4: Image already exists 
Digest: sha256:e73748392d3e86d453e8fdaa38cfe2c549ffbe7349153e72a8222adac02253df
[appadmin@CentOS sysconfig]$ 

浏览器登录http://172.21.28.161:5000/v2/_catalog,此时会显示

{"repositories":["centos"]}


7.验证私有仓库的镜像,先删掉原来的172.21.28.161:5000/centos:6.7,然后从私有仓库下载

[appadmin@CentOS]$ <span style="color:#FF0000;">sudo docker rmi 172.21.28.161:5000/centos:6.7</span>
Untagged: 172.21.28.161:5000/centos:6.7
[appadmin@CentOS]$ 
[appadmin@CentOS]$ <span style="color:#FF0000;">sudo docker images</span>
REPOSITORY                       TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
hub.c.163.com/library/registry   latest              71adeb46c789        2 weeks ago         33.27 MB
hub.c.163.com/library/centos     6.7                 a8b4df3be85c        4 weeks ago         190.6 MB
[appadmin@CentOS]$
[appadmin@CentOS]$ <span style="color:#FF0000;">sudo docker pull 172.21.28.161:5000/centos:6.7</span>
6.7: Pulling from 172.21.28.161:5000/centos
3690474eb5b4: Already exists 
3624df1f7cf0: Already exists 
505dff91e9c8: Already exists 
2352e8cfa843: Already exists 
a8b4df3be85c: Already exists 
Digest: sha256:e73748392d3e86d453e8fdaa38cfe2c549ffbe7349153e72a8222adac02253df
Status: Downloaded newer image for 172.21.28.161:5000/centos:6.7
[appadmin@CentOS]$
[appadmin@CentOS]$ <span style="color:#FF0000;">sudo docker images</span>
REPOSITORY                       TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
hub.c.163.com/library/registry   latest              71adeb46c789        2 weeks ago         33.27 MB
<span style="color:#3333FF;">172.21.28.161:5000/centos        6.7                 a8b4df3be85c        4 weeks ago         190.6 MB</span>
hub.c.163.com/library/centos     6.7                 a8b4df3be85c        4 weeks ago         190.6 MB
[appadmin@CentOS]$



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值