下载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