導讀 | docker 是Linux下面的容器技術,是目前最火的開源技術之一,上次我們瞭解了docker的基礎知識,docker的容器,倉庫,鏡像等,接下來我們就一起來看下本地倉庫的搭建吧。 |
# yum install -y python-devel libevent-devel python-pip gcc xz-devel # pip install docker-registry
也可以從 docker-registry (https://github.com/docker/docker-registry)項目下載源碼進行安裝。
# docker run -d -p 5000:5000 registry #將使用官方的 registry 鏡像來啓動本地的私有倉庫,但是並沒有啓動,只是爲你創建好
默認情況下,會將倉庫存放於容器的 /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 鏡像比較小,沒有的建議先下載:
# 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的時候就會報上面的錯誤。
爲了解決這個問題需要在啓動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
本文轉載自:http://www.linuxprobe.com/docker-repo-local.html
免費提供最新Linux技術教程書籍,爲開源技術愛好者努力做得更多更好:http://www.linuxprobe.com/