設定檔配置
vi /opt/registry/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
執行
docker run -d -p 5000:5000 --privileged=true -v /opt/registry:/var/lib/registry -v /opt/registry/config.yml:/etc/docker/registry/config.yml --name registry registry
看見{}為正常啟動倉庫
客端配置
vi /etc/sysconfig/docker
OPTIONS='--insecure-registry docker.tony:5000' #CentOS 7 other_args='--insecure-registry docker.tony:5000' #CentOS 6
重啟/etc/init.d/docker restart
上傳image
下載image
docker pull docker.tony:5000/test:latest
查看下載的image
docker image
用curl查看本地倉庫的鏡像列表
curl http://docker.tony:5000/v2/_catalog
用curl 查看鏡像的tag列表
curl http://docker.tony:5000/v2/test/tags/list
刪除倉庫的image
curl --header "Accept: application/vnd.docker.distribution.manifest.v2+json" -I -X HEAD http://docker.tony:5000/v2/test/manifests/latest
刪除倉庫的API DELETE /v2/<name>/manifests/<reference>
curl -v -X DELETE http://docker.tony:5000/v2/test/manifests/sha256:8f7d57e3e85ca4395f707fdbac8aca85595a09ebfafe304ebe02d03e82891378
或是直接到倉庫的實體位子刪除
cd /opt/registry/docker/registry/v2/repositories
rm /test
如果要設定帳密方式才能使用倉庫的話如下
設定帳號密碼檔
mkdir -p /opt/registry/auth docker run --entrypoint htpasswd registry -Bbn tony 123456 > auth/htpasswd
重新執行registry
docker run -d -p 5000:5000 --restart=always --privileged=true --name registry \ -v /opt/registry:/var/lib/registry \ -v /opt/registry/config.yml:/etc/docker/registry/config.yml \ -v /opt/registry/auth:/auth \ -e "REGISTRY_AUTH=htpasswd" \ -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \ -e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \ registry
之後在客端上要使用必需要登入才能正常在倉庫推送
登入
docker login -u tony -p 123456 -e [email protected] docker.tony:5000
退出
docker logout docker.tony:5000
指令查詢
curl -i -k -v http://tony:[email protected]:5000/v2/_catalog
拉鏡像庫出錯出現錯誤 如下
Error response from daemon: Get https://xxx:5000/v1/_ping: http: server gave HTTP
linux解決方式
vi /etc/docker/daemon.json
{ "insecure-registries":["myregistry.example.com:5000"] }
重啟docker服務
sudo service docker restart
windows10 解決方式