转载:https://www.cnblogs.com/chen2ha/p/18469181
查看私有仓库有哪些镜像
如果私有仓库带有认证,在使用 curl 命令的时候需要带上 -u 参数
使用方法:
curl -XGET -u admin:admin http://192.168.91.18:5000/v2/_catalog
curl -XGET -u admin:admin http://192.168.91.18:5000/v2/_catalog
输出的格式为 json
{"repositories":["centos","debian","mysql","nginx","php"]}
查看私有仓库镜像的tag
使用方法:
curl -XGET -u <仓库用户名>:<用户名密码> http://<仓库ip地址>:<仓库端口>/v2/<镜像名称>/targs/list
curl -XGET -u admin:admin http://192.168.91.18:5000/v2/centos/tags/list
输出的格式为 json:
{"name":"centos","tags":["latest","7"]}
删除私有仓库指定镜像
- 确认是否开启删除功能(如果没有开启,执行删除镜像操作的时候,会返回如下两种结果)
{"errors":[{"code":"UNSUPPORTED","message":"The operation is unsupported."}]}
HTTP/1.1 405 Method Not Allowed Content-Type: application/json; charset=utf-8 Docker-Distribution-Api-Version: registry/2.0 X-Content-Type-Options: nosniff Date: Fri, 18 Mar 2022 04:12:22 GMT Content-Length: 78
- 查找 registry 容器
docker ps | grep registry
- 进入容器
registry 进入容器的终端是 sh docker exec -it 3745255afa90 sh
- 一般都是在
/etc/docker/registry/config.yml
registry 镜像里面有 vi 没有 vim vi /etc/docker/registry/config.yml
- 我拉取的 registry 镜像默认没有配置 delete 功能
version: 0.1 log: fields: service: registry storage: cache: blobdescriptor: inmemory filesystem: rootdirectory: /var/lib/registry # 增加这里的 delete 和 enabled ,注意 yaml 语法格式 # 如果有 delete ,并且 enable 为 true 表示已经开启了删除功能 delete: enabled: true http: addr: :5000 headers: X-Content-Type-Options: [nosniff] health: storagedriver: enabled: true interval: 10s threshold: 3
- 修改完成后,重启 registry 容器
docker restart 3745255afa90
获取指定镜像的 hash 值
使用方法
curl --header "Accept:application/vnd.docker.distribution.manifest.v2+json" -I \ -u <仓库用户名>:<用户名密码> http://<仓库ip地址>:<仓库端口>/v2/<镜像名称>/manifests/<镜像 tag>
curl -I -XGET --header "Accept:application/vnd.docker.distribution.manifest.v2+json" \ -u admin:admin http://192.168.91.18:5000/v2/centos/manifests/latest
Docker-Content-Digest 这里就会出现镜像的 hash 值
HTTP/1.1 200 OK Content-Length: 529 Content-Type: application/vnd.docker.distribution.manifest.v2+json Docker-Content-Digest: sha256:a1801b843b1bfaf77c501e7a6d3f709401a1e0c83863037fa3aab063a7fdb9dc Docker-Distribution-Api-Version: registry/2.0 Etag: "sha256:a1801b843b1bfaf77c501e7a6d3f709401a1e0c83863037fa3aab063a7fdb9dc" X-Content-Type-Options: nosniff Date: Fri, 18 Mar 2022 04:06:42 GMT
其实如果能登录 Docker-registry 服务器registry挂载的目录,能直接看到这个sha256的值

删除私有仓库中的镜像
使用方法
curl -I -XDELETE -u <仓库用户名>:<用户名密码> \ http://<仓库ip地址>:<仓库端口>/v2/<镜像名称>/manifests/<获取的 hash 值>
curl -I -XDELETE -u admin:admin \ http://192.168.91.18:5000/v2/centos/manifests/sha256:a1801b843b1bfaf77c501e7a6d3f709401a1e0c83863037fa3aab063a7fdb9dc
返回的状态码是 202
HTTP/1.1 202 Accepted Docker-Distribution-Api-Version: registry/2.0 X-Content-Type-Options: nosniff Date: Fri, 18 Mar 2022 04:24:23 GMT Content-Length: 0
再次查看 centos 镜像的 tag 列表
curl -XGET -u admin:admin http://192.168.91.18:5000/v2/centos/tags/list
现在只有一个 7 这个 tag 的镜像了
{"name":"centos","tags":["7"]}