1, 创建 registry 服务
- [[email protected] ~]# docker pull registry
- [[email protected] ~]# docker run -d -v /opt/registry:/var/lib/registry -p 5000:5000 --restart=always --name registry registry 异常退出重启 registry 服务策略: restart
- [[email protected] ~]# 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 问题
- [[email protected] ~]# cat /etc/docker/daemon.JSON 配置私有仓库可信任
- {
- "registry-mirrors": ["http://hub-mirror.c.163.com"],
- "insecure-registries":["192.168.19.132:5000"]
- }
- [[email protected] ~]#
2, 查看镜像信息
测试, 查看镜像名
- [[email protected] ~]# curl -s -XGET localhost:5000/v2/_catalog
- {
- "repositories":["lnmp-php","mysql","nginx","tomcat","tomcat-app"]
- }
- [[email protected] ~]# curl -s -XGET localhost:5000/v2/_catalog | python -mjson.tool
- {
- "repositories": [
- "lnmp-php",
- "mysql",
- "nginx",
- "tomcat",
- "tomcat-app"
- ]
- }
[[email protected] ~]#
测试, 查看镜像 tag
- [[email protected] ~]# curl -s -XGET localhost:5000/v2/_catalog
- [[email protected] ~]# curl -s -XGET localhost:5000/v2/lnmp-PHP/tags/list
- {
- "name":"lnmp-php","tags":["base"]
- }
- [[email protected] ~]# curl -s -XGET localhost:5000/v2/lnmp-PHP/tags/list | python -mjson.tool
- {
- "name": "lnmp-php",
- "tags": [
- "base"
- ]
- }
- [[email protected] ~]#
测试, 查看镜像 reversion
- [[email protected] ~]# ls /opt/registry/docker/registry/v2/repositories/lnmp-PHP/_manifests/revisions/sha256/
- 88a445510f8789fc9a8f1e0f9646c985825bce5d7d66d8a60218f320691a6a93
- [[email protected] ~]# du -sch /opt/registry/docker/registry/v2/
- 867M /opt/registry/docker/registry/v2/
867M 总用量
[[email protected] ~]#
3, 删除镜像信息
测试, 删除镜像
删除镜像, 之前需要启动删除
- [[email protected] ~]# docker exec -it registry /bin/sh
- / # vi /etc/docker/registry/config.YAML (开启删除模式)
- storage:
- delete:
- enabled: true
- [[email protected] ~]# docker exec -it registry /bin/sh 删除之前查看大小
- / # du -sch
- [[email protected] ~]# curl -X DELETE localhost:5000/v2/lnmp-PHP/manifests/sha256:88a445510f8789fc9a8f1e0f9646c985825bce5d7d66d8a60218f320691a6a93 删除镜像
- [[email protected] ~]# docker exec -it registry /bin/sh
- / # registry garbage-collect /etc/docker/registry/config.YAML 进入容器, 垃圾回收
- / # du -sch 回收之后, 镜像删除
652.1M .
652.1M total
4, 清理镜像目录
- [[email protected] ~]# curl -s -XGET localhost:5000/v2/_catalog
- [[email protected] ~]# rm -fr /opt/registry/docker/registry/v2/repositories/lnmp-PHP/
自此, 容器 registry 整个过程完成.
来源: http://www.bubuko.com/infodetail-3086645.html