版本: Docker version 18.03.1-ce, build 9ee9f40
參考官方文檔:
https://docs.docker.com/samples/library/registry/#run-a-local-registry-quick-version
https://docs.docker.com/registry/deploying/
https://docs.docker.com/registry/insecure/
下載registry鏡像
docker pull registry
去海外默認地址下載, 網(wǎng)上說有墻胯府,但我用著是沒墻介衔,可以下載。
啟動鏡像
創(chuàng)建宿主機保存鏡像的目錄
mkdir -p /root/my_docker_registry
啟動 服務
docker run -d -p 5000:5000 --restart always -v /root/my_docker_registry:/var/lib/registry registry
[root@node205 my_docker_registry]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5b0159edad4b registry "/entrypoint.sh /etc…" 6 seconds ago Up 4 seconds 0.0.0.0:5000->5000/tcp eloquent_poincare
可以使用 docker inspect 5b0159edad4b 查看該registry的詳細信息骂因。
驗證及配置
- 直接push一個鏡像
[root@node205 my_docker_registry]# docker push node205:5000/hello-world
The push refers to repository [node205:5000/hello-world]
An image does not exist locally with the tag: node205:5000/hello-world
需要先打tag 炎咖。
- 打tag 后push
docker tag hello-world node205:5000/hello-world
[root@node205 my_docker_registry]# docker push node205:5000/hello-world
The push refers to repository [node205:5000/hello-world]
Get https://node205:5000/v2/: Gateway Timeout
或者
[root@node205 docker]# docker push 10.30.16.205:5000/hello-world
The push refers to repository [10.30.16.205:5000/hello-world]
2b8cbd0846c5: Retrying in 1 second
received unexpected HTTP status: 501 Unsupported method ('POST')
報錯原因: 私有倉庫默認使用 https , 需要配置為使用http ; 另外乘盼,本環(huán)境使用了外網(wǎng)代理升熊, 發(fā)現(xiàn)連接私有倉庫會通過代理,需要配置不走代理绸栅。
參見官網(wǎng): https://docs.docker.com/registry/insecure/#deploy-a-plain-http-registry
https://docs.docker.com/config/daemon/systemd/#httphttps-proxy
- /etc/docker/daemon.json 編輯
{
"insecure-registries" : ["myregistrydomain.com:5000"]
}
(通過日志發(fā)現(xiàn)级野,當啟用insecure-registries時,會先嘗試https 阴幌,不通勺阐,再使用http進行處理卷中。 生產(chǎn)環(huán)境不建議使用之矛双。)
- 配置本地地址不走代理
編輯/etc/systemd/system/docker.service.d/http-proxy.conf 和 /etc/systemd/system/docker.service.d/https-proxy.conf
[Service]
Environment="HTTP_PROXY=http://proxy.example.com:80/" "NO_PROXY=localhost,127.0.0.1,docker-registry.somecorporation.com"
[Service]
Environment="HTTPS_PROXY=https://proxy.example.com:443/" "NO_PROXY=localhost,127.0.0.1,node205"
- 重啟服務
systemctl daemon-reload
systemctl restart docker
網(wǎng)頁驗證
http://10.30.16.205:5000/v2/_catalog
可以看到 {"repositories":["hello-world"]}
其他節(jié)點配置使用
配置代理中增加NO_PROXY, 同master上配置
配置daemon.json 蟆豫,同master上配置
使用 docker pull 或push 從私有倉庫中下載或上傳