版權聲明:本文由田飛雨原創文章,轉載請註明出處:
文章原文連接:https://www.qcloud.com/community/article/94html
來源:騰雲閣 https://www.qcloud.com/communitypython
去中央倉庫下載鏡像有時候很是的慢,因此 docker 本地倉庫和 gitlab 相似,都是爲了便於公司內部人員的使用。git
本次實驗環境:騰訊雲服務器 CentOS 6.7 x86_64github
# yum install -y python-devel libevent-devel python-pip gcc xz-devel
# pip install docker-registry
docker
也能夠從 docker-registry 項目下載源碼進行安裝。shell
# docker run -d -p 5000:5000 registry #將使用官方的 registry 鏡像來啓動本地的私有倉庫,可是並無啓動,只是爲你建立好
vim
默認狀況下,會將倉庫存放於容器的 /tmp/registry 目錄下,若是容器被刪除,則數據也會丟失,因此咱們能夠經過 -v 參數來將鏡像文件存放在本地的指定路徑:服務器
# docker run -d -p 5000:5000 -v /opt/data/registry:/tmp/registry registry
# docker start $(docker ps -l | grep registry | awk '{print $1}') #啓動倉庫
要在本地倉庫上傳鏡像,首先須要標記一個鏡像,如下標記 busybox ,因爲 busybox 鏡像比較小,沒有的建議先下載:curl
# docker pull buxybox # docker tag busybox 192.168.0.232:5000/busybox # 對 buxybox 鏡像進行標記 # docker images #查看標記的鏡像 # docker push 192.168.0.232:5000/busybox #而後開始上傳吧 2016/06/14 11:01:17 Error: Invalid registry endpoint https://192.168.0.232:5000/v1/: Get https://192.168.0.232:5000/v1/_ping: dial tcp 192.168.0.232:5000: connection refused. If this private registry supports only HTTP or HTTPS with an unknown CA certificate, please add `--insecure-registry 192.168.0.232: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/192.168.0.232:5000/ca.crt
呵呵,報錯了!由於Docker從1.3.X以後默認docker registry使用的是https,因此當用docker pull命令下載遠程鏡像時,若是遠程docker registry是非https的時候就會報上面的錯誤。tcp
爲了解決這個問題須要在啓動docker server時增長啓動參數:
# vim /etc/sysconfig/docker #ip 換爲本身的ip other_args="--insecure-registry 192.168.0.232:5000" #默認爲空的 # service docker restart #重啓docker # docker start $(docker ps -l | grep registry | awk '{print $1}') #啓動 registry # docker push 192.168.0.232:5000/busybox #而後從新上傳吧,此次確定成功 # curl http://192.168.0.232:5000/v1/search #查看上傳的鏡像 {"num_results": 1, "query": "", "results": [{"description": "", "name": "library/busybox"}]}
注意: /v1 表明 registry 的版本,使用 docker pull 安裝的默認爲 v1 版本。
測試:
使用另外一臺機器 pull 本地的私有倉庫,可是要在 private registry 上使用 SSL,另外一種就是強制使用普通方式,仍然像上面同樣,在配置文件中加上如下參數:
other_args="--insecure-registry 192.168.0.232:5000"
重啓 docker 服務,而後 pull:
[root@sta docker]# docker pull 192.168.0.232:5000/busybox Pulling repository 192.168.0.232:5000/busybox 437595becdeb: Download complete 437595becdeb: Pulling image (latest) from 192.168.0.232:5000/busybox Status: Image is up to date for 192.168.0.232:5000/busybox:latest