博客列表 >docker-registry 私有仓库镜像 之 查看与删除

docker-registry 私有仓库镜像 之 查看与删除

哈
原创
2022年07月04日 10:39:12653浏览

镜像下载、域名解析、时间同步请点击 阿里云开源镜像站

查看私有仓库有哪些镜像

如果私有仓库带有认证,在使用 curl 命令的时候需要带上 -u 参数

使用方法:

curl -XGET -u <仓库用户名>:<用户名密码> http://<仓库ip地址>:<仓库端口>/v2/_catalog

  1. curl -XGET -u admin:admin http://192.168.91.18:5000/v2/_catalog

输出的格式为 json

  1. {"repositories":["centos","debian","mysql","nginx","php"]}

如果输出的镜像很多,可以用 python 格式化 json 格式,方便查看

  1. curl -s -XGET -u admin:admin http://192.168.91.18:5000/v2/_catalog | python -m json.tool

这样看,也会直观很多

  1. {
  2. "repositories": [
  3. "centos",
  4. "debian",
  5. "mysql",
  6. "nginx",
  7. "php"
  8. ]
  9. }

查看私有仓库镜像的tag

使用方法:

curl -XGET -u <仓库用户名>:<用户名密码> http://<仓库ip地址>:<仓库端口>/v2/<镜像名称>/targs/list

  1. curl -XGET -u admin:admin http://192.168.91.18:5000/v2/centos/tags/list

输出的格式为 json

  1. {"name":"centos","tags":["latest","7"]}

如果输出的 tag 很多,可以用 python 格式化 json 格式,方便查看

  1. curl -s -XGET -u admin:admin http://192.168.91.18:5000/v2/centos/tags/list | python -m json.tool

这样看,也会直观很多

  1. {
  2. "name": "centos",
  3. "tags": [
  4. "latest",
  5. "7"
  6. ]
  7. }

删除私有仓库指定镜像

确认是否开启删除功能

如果没有开启,执行删除镜像操作的时候,会返回如下两种结果

  1. {"errors":[{"code":"UNSUPPORTED","message":"The operation is unsupported."}]}
  1. HTTP/1.1 405 Method Not Allowed
  2. Content-Type: application/json; charset=utf-8
  3. Docker-Distribution-Api-Version: registry/2.0
  4. X-Content-Type-Options: nosniff
  5. Date: Fri, 18 Mar 2022 04:12:22 GMT
  6. Content-Length: 78

查找 registry 容器

  1. docker ps | grep registry

以自己实际获取的信息为准

  1. 3745255afa90 registry "/entrypoint.sh /etc…" About an hour ago Up About an hour 0.0.0.0:5000->5000/tcp, :::5000->5000/tcp registry

进入容器

registry 进入容器的终端是 sh

  1. docker exec -it 3745255afa90 sh

一般都是在 /etc/docker/registry/config.yml

registry 镜像里面有 vi 没有 vim

  1. vi /etc/docker/registry/config.yml

我拉取的 registry 镜像默认没有配置 delete 功能

  1. version: 0.1
  2. log:
  3. fields:
  4. service: registry
  5. storage:
  6. cache:
  7. blobdescriptor: inmemory
  8. filesystem:
  9. rootdirectory: /var/lib/registry
  10. # 增加这里的 delete 和 enabled ,注意 yaml 语法格式
  11. # 如果有 delete ,并且 enable 为 true 表示已经开启了删除功能
  12. delete:
  13. enabled: true
  14. http:
  15. addr: :5000
  16. headers:
  17. X-Content-Type-Options: [nosniff]
  18. health:
  19. storagedriver:
  20. enabled: true
  21. interval: 10s
  22. threshold: 3

修改完成后,重启 registry 容器

  1. docker restart 3745255afa90

获取指定镜像的 hash 值

使用方法

curl —header “Accept:application/vnd.docker.distribution.manifest.v2+json” -I \ -u <仓库用户名>:<用户名密码> http://<仓库ip地址>:<仓库端口>/v2/<镜像名称>/manifests/<镜像 tag>

  1. curl -I -XGET --header "Accept:application/vnd.docker.distribution.manifest.v2+json" \
  2. -u admin:admin http://192.168.91.18:5000/v2/centos/manifests/latest

Docker-Content-Digest 这里就会出现镜像的 hash 值

  1. HTTP/1.1 200 OK
  2. Content-Length: 529
  3. Content-Type: application/vnd.docker.distribution.manifest.v2+json
  4. Docker-Content-Digest: sha256:a1801b843b1bfaf77c501e7a6d3f709401a1e0c83863037fa3aab063a7fdb9dc
  5. Docker-Distribution-Api-Version: registry/2.0
  6. Etag: "sha256:a1801b843b1bfaf77c501e7a6d3f709401a1e0c83863037fa3aab063a7fdb9dc"
  7. X-Content-Type-Options: nosniff
  8. Date: Fri, 18 Mar 2022 04:06:42 GMT

删除私有仓库中的镜像

使用方法

curl -I -XDELETE -u <仓库用户名>:<用户名密码> \ http://<仓库ip地址>:<仓库端口>/v2/<镜像名称>/manifests/<获取的 hash 值>

  1. curl -I -XDELETE -u admin:admin \
  2. http://192.168.91.18:5000/v2/centos/manifests/sha256:a1801b843b1bfaf77c501e7a6d3f709401a1e0c83863037fa3aab063a7fdb9dc

返回的状态码是 202

  1. HTTP/1.1 202 Accepted
  2. Docker-Distribution-Api-Version: registry/2.0
  3. X-Content-Type-Options: nosniff
  4. Date: Fri, 18 Mar 2022 04:24:23 GMT
  5. Content-Length: 0

再次查看 centos 镜像的 tag 列表

  1. curl -XGET -u admin:admin http://192.168.91.18:5000/v2/centos/tags/list

现在只有一个 7 这个 tag 的镜像了

  1. {"name":"centos","tags":["7"]}

原文链接:https://blog.csdn.net/u010383467/article/details/123571707

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议