新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
Linux中搭建Docker私有倉(cāng)庫(kù)
使用Docker私有倉(cāng)庫(kù)可以幫助我們節(jié)省網(wǎng)絡(luò)帶寬,針對(duì)于每個(gè)鏡像不用每個(gè)人都去中央倉(cāng)庫(kù)上面去下載,只需要從私有倉(cāng)庫(kù)中下載即可,還可以提供鏡像資源利用,針對(duì)于公司內(nèi)部使用的鏡像,推送到本地的私有倉(cāng)庫(kù)中,以供公司內(nèi)部相關(guān)人員使用。

修改配置http訪(fǎng)問(wèn)
[root@test01 ~]# cat /etc/docker/daemon.json
{"registry-mirrors": ["https://registry.docker-cn.com"],"insecure-registries":["192.168.1.30:5000"]}
如果不這樣配置,結(jié)果如下。這個(gè)問(wèn)題可能是由于客戶(hù)端采用https,docker registry未采用https服務(wù)所致。一種處理方式是把客戶(hù)對(duì)地址“192.168.1.30:5000”請(qǐng)求改為http
[root@test01 ~]# docker push 192.168.1.30:5000/centos
The push refers to a repository [192.168.1.30:5000/centos]
Get https://192.168.1.30:5000/v1/_ping: http: server gave HTTP response to HTTPS client
使用容器運(yùn)行docker-registry
[root@test01 ~]# docker run -d -p 5000:5000 --privileged=true -v /opt/data/registry:/tmp/registry --name='docker-registry' registry
參數(shù)說(shuō)明:
-v /opt/data/registry:/tmp/registry :默認(rèn)情況下,會(huì)將倉(cāng)庫(kù)存放于容器內(nèi)的/tmp/registry目錄下,指定本地目錄掛載到容器
–privileged=true :CentOS7中的安全模塊selinux把權(quán)限禁掉了,參數(shù)給容器加特權(quán),不加上傳鏡像會(huì)報(bào)權(quán)限錯(cuò)誤(OSError: [Errno 13] Permission denied: ‘/tmp/registry/repositories/liibrary’)或者(Received unexpected HTTP status: 500 Internal Server Error)錯(cuò)誤
上傳鏡像
[root@test01 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/wordpress latest 346b1443b020 30 hours ago 407 MB
[root@test01 ~]# docker push 192.168.1.30:5000/wordpress
The push refers to a repository [192.168.1.30:5000/wordpress]
An image does not exist locally with the tag: 192.168.1.30:5000/wordpress
[root@test01 ~]#
根據(jù)提示,我們知道需要修改一下tag才能上傳
[root@test01 ~]# docker tag docker.io/wordpress 192.168.1.30:5000/wordpress
[root@test01 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.1.30:5000/wordpress latest 346b1443b020 30 hours ago 407 MB
docker.io/wordpress latest 346b1443b020 30 hours ago 407 MB
[root@test01 ~]# docker push 192.168.1.30:5000/wordpress
The push refers to a repository [192.168.1.30:5000/wordpress]
3d7c1bb6ce9f: Pushed
從私有倉(cāng)庫(kù)中下載
[root@test01 ~]# docker pull 192.168.1.30:5000/wordpress
客戶(hù)端永久配置使用私有倉(cāng)庫(kù)
加入ADD_REGISTRY='--add-registry 192.168.1.30:5000'
[root@test01 ~]# cat /etc/sysconfig/docker
# /etc/sysconfig/docker
# Modify these options if you want to change the way the docker daemon runs
OPTIONS='--selinux-enabled --log-driver=journald --signature-verification=false -H unix:///var/run/docker.sock -H 0.0.0.0:2376'
ADD_REGISTRY='--add-registry 192.168.1.30:5000'
if [ -z "${DOCKER_CERT_PATH}" ]; then
DOCKER_CERT_PATH=/etc/docker
fi
本文標(biāo)題:Linux中搭建Docker私有倉(cāng)庫(kù)
文章網(wǎng)址:http://fisionsoft.com.cn/article/cdcojjg.html


咨詢(xún)
建站咨詢(xún)
