docker之搭建私有倉(cāng)庫(kù)

因?yàn)榍懊嬗辛艘恍?Docker 基礎(chǔ),我就不再多羅嗦了

1. 修改配置http訪問(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)題可能是由于客戶端采用https,docker registry未采用https服務(wù)所致。一種處理方式是把客戶對(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
2. 使用容器運(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ò)誤

3. 上傳鏡像
[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
4. 從私有倉(cāng)庫(kù)中下載
[root@test01 ~]# docker pull 192.168.1.30:5000/wordpress
5. 客戶端永久配置使用私有倉(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
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容