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

  • docker-registry 私有仓库镜像 之 查看与删除已关闭评论
  • 135 次浏览
  • A+
所属分类:linux技术
摘要

镜像下载、域名解析、时间同步请点击 阿里云开源镜像站如果私有仓库带有认证,在使用 curl 命令的时候需要带上 -u 参数

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

查看私有仓库有哪些镜像

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

使用方法:

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

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

输出的格式为 json

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

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

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

这样看,也会直观很多

{     "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"]} 

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

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

这样看,也会直观很多

{     "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 

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

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

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 

删除私有仓库中的镜像

使用方法

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"]} 

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