如果私有仓库带有认证,在使用 curl 命令的时候需要带上 -u 参数
使用方法:
curl -XGET -u
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"
]
}
使用方法:
curl -XGET -u
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"
]
}
如果未启用,则在执行删除镜像操作时将返回以下两个结果
[En]
If it is not enabled, the following two results will be returned when you perform the delete mirror operation
{"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
根据你实际获得的信息。
[En]
Based on the information you have actually obtained.
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
使用方法
curl –header “Accept:application/vnd.docker.distribution.manifest.v2+json” -I \ -u
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
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"]}
Original: https://www.cnblogs.com/helong-123/p/16442070.html
Author: 萌褚
Title: docker-registry 私有仓库镜像 之 查看与删除
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/523201/
转载文章受原作者版权保护。转载请注明原作者出处!