Docker 倉庫管理
* docker pull registry //下載registry 鏡像,registy爲docker官方提供的一個倉庫鏡像,我們可以用它來創建本地的docker私有倉庫。
* docker run -d -p 5000:5000 registy //以registry鏡像啓動容器,監聽5000端口,#端口映射5000,因爲不在一個局域網,裏外的端口不通,所以需要映射。
* curl 127.0.0.1:5000 //可以訪問它
下面我們來把其中一個鏡像上傳到私有倉庫
* docker tag wyp_test 172.7.15.106:5000/wyp //標記一下tag,必須要帶有私有倉庫的ip:port,才能上傳上去。
* docker push 172.7.15.106:5000/centos //此時報錯了類似如下
Error response from daemon: invalid registry endpoint https://172.7.15.106:5000/v0/: unable to ping registry endpoint https://172.7.15.106:5000/v0/
v2 ping attempt failed with error: Get https://172.7.15.106:5000/v2/: EOF
v1 ping attempt failed with error: Get https://172.7.15.106:5000/v1/_ping: EOF. If this private registry supports only HTTP or HTTPS with an unknown CA certificate, please add `--insecure-registry 172.7.15.106:5000` to the daemon's arguments. In the case of HTTPS, if you have access to the registry's CA certificate, no need for the flag; simply place the CA certificate at /etc/docker/certs.d/172.7.15.106:5000/ca.crt
* 這是因爲Docker從1.3.X之後,與docker registry交互默認使用的是https,然而此處搭建的私有倉庫只提供http服務,所以當與私有倉庫交互時就會報上面的錯誤。爲了解決這個問題需要在啓動docker server時增加啓動參數爲默認使用http訪問。解決該問題的方法爲:
* vi /etc/init.d/docker
把 $exec -d $other_args 改爲
$exec -d --insecure-registry 172.7.15.106:5000 $other_args
然後重啓docker
service docker restart
再啓動registry容器
docker start registry_container_id
curl http://172.7.15.106:5000/v1/search //可以查看私有倉庫裏面的所有鏡像