和Mavan的管理一样,Dockers不仅提供了一个中央仓库,同时也允许我们使用registry搭建本地私有仓库。
使用私有仓库有许多优点:
1.节省网络带宽,针对于每个镜像不用每个人都去中央仓库上面去下载,只需要从私有仓库中下载即可;
使用push命令
使用私有仓库有许多优点:
1.节省网络带宽,针对于每个镜像不用每个人都去中央仓库上面去下载,只需要从私有仓库中下载即可;
2.提供镜像资源利用,针对于公司内部使用的镜像,推送到本地的私有仓库中,以供公司内部相关人员使用。
准备2台centOS7,192.168.174.128,192.168.174.129,都安装好docker了。实验在128中安装registry,在129中那从128中pull镜像,也能push镜像到128。
1.安装启动registry
128上操作。
下载registry镜像.
[root@localhost ~]# docker pull registry
默认情况下,会将仓库存放于容器内的/tmp/registry目录下,这样如果容器被删除,则存放于容器中的镜像也会丢失,所以我们一般情况下会指定本地一个目录挂载到容器内的/tmp/registry下,如下:
[root@localhost opt]# docker run -d -p 5000:5000 -v /opt/registry:/tmp/registry docker.io/registry
2.pull/push镜像
把129上的某个镜像tag下,然后试试能否push到128的registry容器中.
[root@localhost ~]# docker tag dreambroken/hello-world:latest 192.168.174.128:5000/hello:latest
使用push命令
[root@localhost ~]# docker push 192.168.174.128:5000/hello:latest
The push refers to a repository [192.168.174.128:5000/hello]
unable to ping registry endpoint https://192.168.174.128:5000/v0/
v2 ping attempt failed with error: Get https://192.168.174.128:5000/v2/: http: server gave HTTP response to HTTPS client
v1 ping attempt failed with error: Get https://192.168.174.128:5000/v1/_ping: http: server gave HTTP response to HTTPS client
[root@localhost ~]#
发现报错了,使用的是https,修改/etc/sysconfig/docker(这是centOS7下的1.10.3docker)文件,加上ADD_REGISTRY='--add-registry 192.168.174.128:5000',INSECURE_REGISTRY='--insecure-registry 192.168.174.128:5000'
重启docker服务
[root@localhost system]# systemctl restart docker
然后push
[root@localhost system]# docker push 192.168.174.128:5000/hello:latest
The push refers to a repository [192.168.174.128:5000/hello]
a02596fdd012: Pushed
latest: digest: sha256:0256e8a36e2070f7bf2d0b0763dbabdd67798512411de4cdcf9431a1feb60fd9 size: 502
[root@localhost system]#
把129上的192.168.174.128:5000/hello删掉,然后重新pull,发现能正常pull下来。