下載registry鏡像
docker pull registry
遠行registry
// -v ~/registry:/var/lib/registry 掛載鏡像目錄
docker run -d -p 5000:5000 -v ~/registry:/var/lib/registry --name uwo_registry registry
上傳鏡像到私有庫
docker pull mongo
docker tag mongo localhost:5000/mongo
docker push localhost:5000/mongo
遠程訪問私有庫
配置/etc/default/docker
DOCKER_OPTS="-H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375"
配置/etc/docker/daemon.json容許HTTP訪問(默認是HTTPS)
{
# 修改獲取鏡像源
"registry-mirrors": ["https://dhq9bx4f.mirror.aliyuncs.com"],
# 容許HTTP訪問
"insecure-registries":["10.211.55.8:5000"]
}
registry API
查看全部的鏡像
http://10.211.55.8:5000/v2/_catalog
查看鏡像信息
http://10.211.55.8:5000/v2/mongo/tags/list
刪除私有庫中的鏡像
修改config.yml
// 主要添加delete.enabled = true
version: 0.1
log:
fields:
service: registry
storage:
cache:
blobdescriptor: inmemory
filesystem:
rootdirectory: /var/lib/registry
delete:
enabled: true
http:
addr: :5000
headers:
X-Content-Type-Options: [nosniff]
health:
storagedriver:
enabled: true
interval: 10s
threshold: 3
從新run Registry
// 掛載config.yml
docker run -d -p 5000:5000 -v ~/registry:/var/lib/registry -v ~/registry/config.yml:/etc/docker/registry/config.yml --name uwo_registry registry
請求是添加HEADER
Accept: application/vnd.docker.distribution.manifest.v2+json
查詢鏡像
curl -H "Accept: application/vnd.docker.distribution.manifest.v2+json" -I -X GET http://localhost:5000/v2/uwo-web/manifests/latest
// 結果
HTTP/1.1 200 OK
Content-Length: 2212
Content-Type: application/vnd.docker.distribution.manifest.v2+json
Docker-Content-Digest: sha256:94985f90eef634e674a1826cc469381e6ce8f188798308ee79b0045837ee2032
Docker-Distribution-Api-Version: registry/2.0
Etag: "sha256:94985f90eef634e674a1826cc469381e6ce8f188798308ee79b0045837ee2032"
X-Content-Type-Options: nosniff
Date: Tue, 15 Aug 2017 07:12:47 GMT
刪除鏡像
curl -H "Accept: application/vnd.docker.distribution.manifest.v2+json" -X DELETE http://10.211.55.8:5000/v2/uwo-web/manifests/sha256:94985f90eef634e674a1826cc469381e6ce8f188798308ee79b0045837ee2032
進入容器
docker exec -it f50ff19602d /bin/sh
查看容器大小
du -sch /var/lib/registry/
// 結果
373.8M /var/lib/registry/
373.8M total
垃圾回收
registry garbage-collect /etc/docker/registry/config.yml
再次查看容器大小
du -sch /var/lib/registry/
// 結果
126.0M /var/lib/registry/
126.0M total