1、创建registry服务
[root@master ~]# docker pull registry
[root@master ~]# docker run -d -v /opt/registry:/var/lib/registry -p 5000:5000 --restart=always --name registry registry 异常退出重启registry服务策略:restart
[root@master ~]# docker ps |grep registry
2edf4e5a1d91 registry "/entrypoint.sh /e..." 2 weeks ago Up 18 minutes 0.0.0.0:5000->5000/tcp registry
Docker pull获取的镜像地址https://hub.docker.com/search/?q=&type=image,从此处获取仓库镜像。
下载和推送镜像到私有仓库,需要处理https问题
[root@master ~]# cat /etc/docker/daemon.json 配置私有仓库可信任
{
"registry-mirrors": ["http://hub-mirror.c.163.com"],
"insecure-registries":["192.168.19.132:5000"]
}
[root@master ~]#
2、查看镜像信息
测试,查看镜像名
[root@master ~]# curl -s -XGET localhost:5000/v2/_catalog
{"repositories":["lnmp-php","mysql","nginx","tomcat","tomcat-app"]}
[root@master ~]# curl -s -XGET localhost:5000/v2/_catalog | python -mjson.tool
{
"repositories": [
"lnmp-php",
"mysql",
"nginx",
"tomcat",
"tomcat-app"
]
}
[root@master ~]#
测试,查看镜像tag
[root@master ~]# curl -s -XGET localhost:5000/v2/_catalog
[root@master ~]# curl -s -XGET localhost:5000/v2/lnmp-php/tags/list
{"name":"lnmp-php","tags":["base"]}
[root@master ~]# curl -s -XGET localhost:5000/v2/lnmp-php/tags/list | python -mjson.tool
{
"name": "lnmp-php",
"tags": [
"base"
]
}
[root@master ~]#
测试,查看镜像 reversion
[root@master ~]# ls /opt/registry/docker/registry/v2/repositories/lnmp-php/_manifests/revisions/sha256/
88a445510f8789fc9a8f1e0f9646c985825bce5d7d66d8a60218f320691a6a93
[root@master ~]# du -sch /opt/registry/docker/registry/v2/
867M /opt/registry/docker/registry/v2/
867M 总用量
[root@master ~]#
3、删除镜像信息
测试,删除镜像
删除镜像,之前需要启动删除
[root@master ~]# docker exec -it registry /bin/sh
/ # vi /etc/docker/registry/config.yml (开启删除模式)
storage:
delete:
enabled: true
[root@master ~]# docker exec -it registry /bin/sh 删除之前查看大小
/ # du –sch
[root@master ~]# curl -X DELETE localhost:5000/v2/lnmp-php/manifests/sha256:88a445510f8789fc9a8f1e0f9646c985825bce5d7d66d8a60218f320691a6a93 删除镜像
[root@master ~]# docker exec -it registry /bin/sh
/ # registry garbage-collect /etc/docker/registry/config.yml 进入容器,垃圾回收
/ # du -sch 回收之后,镜像删除
652.1M .
652.1M total
4、清理镜像目录
[root@master ~]# curl -s -XGET localhost:5000/v2/_catalog
[root@master ~]# rm -fr /opt/registry/docker/registry/v2/repositories/lnmp-php/
自此,容器registry整个过程完成。