009 centos7搭建docker私有倉庫

1.準備:

    三臺機器:docker

        192.168.20.201    搭建私有倉庫bash

        192.168.20.202    push鏡像curl

        192.168.20.203    pull鏡像測試

2.搭建私有倉庫:

    2-1  下載registry鏡像:   url

        使用 192.168.20.201 機器:spa

docker pull registry

   

    2-2  啓動registry鏡像:    rest

docker run -d -p 5000:5000 -v /tmp/registry:/tmp/registry registry:latest

    默認狀況下,倉庫會將鏡像存放於容器內的/tmp/registry目錄下,若是容器被刪除,則存放於容器中的鏡像也會丟失,因此指定一個目錄掛載到容器內的/tmp/registry下code

3.測試:

    3-1  在192.168.20.202 隨便準備一個鏡像,搞個 helloworld 鏡像io

    

    3-2  修改該鏡像標籤class

docker tag docker.io/hello-world:latest 192.168.20.201:5000/hello-world:latest

    重命名爲:私有倉庫所在機器IP + 端口號 + 鏡像name + 鏡像tag

    3-3 push鏡像

docker push 192.168.20.201:5000/hello-world:latest

        會出現如下錯誤:

        緣由:與docker registry交互時,默認使用的是https,而搭建的私有倉庫只提供http服務

        解決辦法:修改三臺機器的 /etc/sysconfig/docker 配置文件,添加 

        --insecure-registry 192.168.20.201:5000(倉庫所在電腦地址)

            或者是

exec "$DOCKER" -d $DOCKER_OPTS --insecure-registry 192.168.20.201:5000

    3-4 重啓三臺機器的docker

systemctl restart docker.service

    3-5 push鏡像

        在 192.168.20.202 執行

docker push 192.168.20.201:5000/hello-world:latest

    3-6 pull鏡像

    在 192.168.20.203 執行

docker pull 192.168.20.203:5000/hello-world

    成功從私有倉庫獲取到hello-world鏡像

    3-7 查看私有倉庫鏡像    

    在 192.168.20.201 執行:

    查看全部鏡像:

curl localhost:5000/v2/_catalog

    查看具體鏡像tag:

curl localhost:5000/v2/hello-world/tags/list

相關文章
相關標籤/搜索