1、系统环境:CentOS 7.3
172.16.0.44 registry 已安装docker
172.16.0.45 client 已安装docker
2、未加密仓库部署
下载registry镜像
docker pull registry
启动一个registry容器
docker run -d -p 5000:5000 -v /opt/registry/:/tmp/registry registry
下载一个需要私有部署的镜像
docker pull redis
修改镜像的tag
docker tag redis 172.16.0.44:5000/redis
上传打完tag的镜像到私有仓库
docker push 172.16.0.44:5000/redis The push refers to a repository [172.16.0.44:5000/redis] Get https://172.16.0.44:5000/v2/: http: server gave HTTP response to HTTPS client
因为从 docker1.3.2 开始,docker registry 默认都是使用v2,使用 https 协议而不是 http
解决办法:
在/etc/docker目录下,创建daemon.json文件,添加如下内容:
{ "insecure-registries":["172.16.0.44:5000"] }
保存退出
systemctl daemon-reload systemctl restart docker
重启后再次上传镜像,会提示如下错误
The push refers to a repository [172.16.0.44:5000/redis] Get http://172.16.0.44:5000/v2/: dial tcp 172.16.0.44:5000: getsockopt: connection refused
这是因为重启docker服务后,刚才创建的registry仓库的容器停止了,重启启动容器,就可以上传成功了
docker push 172.16.0.44:5000/redis The push refers to a repository [172.16.0.44:5000/redis] 2bf5fdee0818: Pushed e23ed9242cd7: Pushed 32f085a1e7bb: Pushed 05d392f56700: Pushed 2b0fb280b60d: Pushed latest: digest: sha256:ee24c6a68d9ce22df1aa743ea4c624cdc74e4d99b78e199d480292675249ebca size: 1364
检查私有仓库是否配置成功
curl http://172.16.0.44:5000/v2/_catalog {"repositories":["redis"]}
在客户端下载私有仓库上的镜像查看成功
docker pull 172.16.0.44:5000/redis
3、加密仓库部署
上传或生产自己的证书文件到仓库服务器上
把证书文件server.key server.pem上传到certs目录下
mkdir -p /etc/docker/certs
启动registry容器
docker run -d -it -p 5000:5000 --restart=always --name zx_registry -v `pwd`/certs:/etc/docker/certs/ -v /opt/registry/:/tmp/registry -e REGISTRY_HTTP_TLS_CERTIFICATE=/etc/docker/certs/server.pem -e REGISTRY_HTTP_TLS_KEY=/etc/docker/certs/server.key registry
拷贝证书文件到客户端
scp certs/server.pem root@172.16.0.45:/etc/pki/ca-trust/source/anchors/
客户端更新证书文件
cd /etc/pki/ca-trust/source/anchors update-ca-trust
后面的操作就同未加密仓库部署一样,下载镜像,镜像打tag,上传镜像到本地仓库,客户端下载私有镜像
知行办公,专业移动办公平台 https://zx.naton.cn/
【总监】十二春秋之,3483099@qq.com;
【Master】zelo,616701261@qq.com;
【运营】狼行天下,897221533@qq.com;
【产品设计】流浪猫,364994559@qq.com;
【体验设计】兜兜,2435632247@qq.com;
【iOS】淘码小工,492395860@qq.com;iMcG33K,imcg33k@gmail.com;
【Android】人猿居士,1059604515@qq.com;思路的顿悟,1217022114@qq.com;
【java】首席工程师MR_W,feixue300@qq.com;
【测试】土镜问道,847071279@qq.com;
【数据】喜乐多,42151960@qq.com;
【安全】保密,你懂的。
本文出自 “践行者” 博客,请务必保留此出处http://bluemooder.blog.51cto.com/12822812/1961299
原文地址:http://bluemooder.blog.51cto.com/12822812/1961299