Linux中如何搭建Docker私有仓库
导读:本文共1909.5字符,通常情况下阅读需要6分钟。同时您也可以点击右侧朗读,来听本文内容。按键盘←(左) →(右) 方向键可以翻页。
摘要: 使用Docker私有仓库可以帮助我们节省网络带宽,针对于每个镜像不用每个人都去中央仓库上面去下载,只需要从私有仓库中下载即可,还可以提供镜像资源利用,针对于公司内部使用的镜像,推送到本地的私有仓库中,以供公司内部相关人员使用。修改配置http访问[root@test01~]#cat/etc/docker/daemon.json{"registry-mi... ...
音频解说
目录
(为您整理了一些要点),点击可以直达。使用Docker私有仓库可以帮助我们节省网络带宽,针对于每个镜像不用每个人都去中央仓库上面去下载,只需要从私有仓库中下载即可,还可以提供镜像资源利用,针对于公司内部使用的镜像,推送到本地的私有仓库中,以供公司内部相关人员使用。
修改配置http访问
[root@test01~]#cat/etc/docker/daemon.json{"registry-mirrors":["https://registry.docker-cn.com"],"insecure-registries":["192.168.1.30:5000"]}
如果不这样配置,结果如下。这个问题可能是由于客户端采用https,docker registry未采用https服务所致。一种处理方式是把客户对地址“192.168.1.30:5000”请求改为http
[root@test01~]#dockerpush192.168.1.30:5000/centosThepushreferstoarepository[192.168.1.30:5000/centos]Gethttps://192.168.1.30:5000/v1/_ping:http:servergaveHTTPresponsetoHTTPSclient
使用容器运行docker-registry
[root@test01~]#dockerrun-d-p5000:5000--privileged=true-v/opt/data/registry:/tmp/registry--name='docker-registry'registry
参数说明:
-v/opt/data/registry:/tmp/registry:默认情况下,会将仓库存放于容器内的/tmp/registry目录下,指定本地目录挂载到容器–privileged=true:CentOS7中的安全模块selinux把权限禁掉了,参数给容器加特权,不加上传镜像会报权限错误(OSError:[Errno13]Permissiondenied:‘/tmp/registry/repositories/liibrary’)或者(ReceivedunexpectedHTTPstatus:500InternalServerError)错误
上传镜像
[root@test01~]#dockerimagesREPOSITORYTAGIMAGEIDCREATEDSIZEdocker.io/wordpresslatest346b1443b02030hoursago407MB[root@test01~]#dockerpush192.168.1.30:5000/wordpressThepushreferstoarepository[192.168.1.30:5000/wordpress]Animagedoesnotexistlocallywiththetag:192.168.1.30:5000/wordpress[root@test01~]#
根据提示,我们知道需要修改一下tag才能上传
[root@test01~]#dockertagdocker.io/wordpress192.168.1.30:5000/wordpress[root@test01~]#dockerimagesREPOSITORYTAGIMAGEIDCREATEDSIZE192.168.1.30:5000/wordpresslatest346b1443b02030hoursago407MBdocker.io/wordpresslatest346b1443b02030hoursago407MB[root@test01~]#dockerpush192.168.1.30:5000/wordpressThepushreferstoarepository[192.168.1.30:5000/wordpress]3d7c1bb6ce9f:Pushed
从私有仓库中下载
[root@test01~]#dockerpull192.168.1.30:5000/wordpress
客户端永久配置使用私有仓库
加入ADD_REGISTRY='--add-registry192.168.1.30:5000'[root@test01~]#cat/etc/sysconfig/docker#/etc/sysconfig/docker#ModifytheseoptionsifyouwanttochangethewaythedockerdaemonrunsOPTIONS='--selinux-enabled--log-driver=journald--signature-verification=false-Hunix:///var/run/docker.sock-H0.0.0.0:2376'ADD_REGISTRY='--add-registry192.168.1.30:5000'if[-z"${DOCKER_CERT_PATH}"];thenDOCKER_CERT_PATH=/etc/dockerfi
</div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
本文:
Linux中如何搭建Docker私有仓库的详细内容,希望对您有所帮助,信息来源于网络。