centos7 Docker私有倉庫搭建

  • 部署Registry

運行命令

docker pull registry
  •  運行Registry
docker run --name registry  -d -p 5000:5000 -v /opt/data/registry:/var/lib/registry  -v /data/config.yml:/etc/docker/registry/config.yml  registry

 

/data/config.yml 這個是什麼呢?我們在下面刪除倉庫鏡像介紹

這裏需要說明一點,在啓動倉庫時,需在配置文件中的storage配置中增加delete=true配置項,允許刪除鏡像。默認的鏡像是沒有這個參數

cat config.yml
 
version: 0.1
log:
  fields:
    service: registry
storage:
  delete:
    enabled: true
  cache:
    blobdescriptor: inmemory
  filesystem:
    rootdirectory: /var/lib/registry
http:
  addr: :5000
  headers:
    X-Content-Type-Options: [nosniff]
health:
  storagedriver:
    enabled: true
    interval: 10s
    threshold: 3

可以看到我們啓動了一個容器,地址爲:10.12.20.24:5000

 

測試

接下來我們就要操作把一個本地鏡像push到私有倉庫中。首先在153機器下pull一個比較小的鏡像來測試(此處使用的是busybox)。

docker pull busybox

接下來修改一下該鏡像的tag。

docker tag busybox 192.168.0.153:5000/busybox

接下來把打了tag的鏡像上傳到私有倉庫。

docker push 192.168.0.153:5000/busybox

可以看到 push 失敗:

 Error: Invalid registry endpoint https://192.168.0.153:5000/v1/: Get https://192.168.0.153:5000/v1/_ping: dial tcp 192.168.0.153:5000: connection refused. If this private registry supports only HTTP or HTTPS with an unknown CA certificate, please add `--insecure-registry 192.168.112.136: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.153:5000/ca.crt 

因爲Docker從1.3.X之後,與docker registry交互默認使用的是https,然而此處搭建的私有倉庫只提供http服務,所以當與私有倉庫交互時就會報上面的錯誤。爲了解決這個問題需要在啓動docker server時增加啓動參數爲默認使用http訪問。修改docker啓動配置文件:

vim  /usr/lib/systemd/system/docker.service 

找到 ExecStart

ExecStart=/usr/bin/dockerd  --insecure-registry 192.168.0.153:5000

紅色字體爲添加的

 

重啓docker:

systemctl daemon-reload
systemctl restart docker

重啓完之後我們再次運行推送命令,把本地鏡像推送到私有服務器上。

docker push 192.168.0.153:5000/busybox

 

接下來我們從私有倉庫中pull下來該鏡像。

sudo docker pull 192.168.0.153:5000/busybox
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章