查看Registry中镜像
- 查看Registry中的所有镜像
curl -X GET http://<registry-url>/v2/_catalog
在Registry URL处替换实际的Registry地址,例如 http://registry.example.com/v2/_catalog
这将返回一个JSON格式的响应,其中包含Registry中的所有镜像。
- 如果出现
Certificate issuer is not recognized
需要加上-k
参数
curl -X GET http://<registry-url>/v2/_catalog -k
curl: (60) Peer's Certificate issuer is not recognized.
More details here: http://curl.haxx.se/docs/sslcerts.html
curl performs SSL certificate verification by default, using a "bundle"
of Certificate Authority (CA) public keys (CA certs). If the default
bundle file isn't adequate, you can specify an alternate file
using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
the bundle, the certificate verification probably failed due to a
problem with the certificate (it might be expired, or the name might
not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
the -k (or --insecure) option.
- 如果返回
{"errors":[{"code":"UNAUTHORIZED","message":"authentication required","detail":[{"Type":"registry","Class":"","Name":"catalog","Action":"*"}]}]}
,这个错误消息表示您未经授权访问Registry。您需要提供认证信息(例如用户名和密码)才能访问Registry。您可以使用以下命令进行身份验证:
curl -u <username>:<password> http://<registry-url>/v2/_catalog
在这个命令中,将和替换为您的凭据,并在处替换为您的Registry地址。
如果您仍然收到类似的错误消息,请确保您具有正确的访问权限,例如,您的账户有权访问Registry。
- 查看特定镜像的所有标签
curl -X GET http://<registry-url>/v2/<image-name>/tags/list
在Registry URL和Image Name处替换实际的Registry地址和镜像名称,例如 http://registry.example.com/v2/my-image/tags/list
这将返回一个JSON格式的响应,其中包含指定镜像的所有标签。
- 查询镜像digest值
命令如下,注意请求头需要加入"Accept: application/vnd.docker.distribution.manifest.v2+json"
,不然会返回错误的digest。
curl --header "Accept:application/vnd.docker.distribution.manifest.v2+json" -I -XGET https://registry.opsxlab.cn/v2/test(镜像路径)/tomcat(镜像名称)/manifests/1.0.0(镜像版本)
返回示例:
[root@master tools]# curl --header "Accept:application/vnd.docker.distribution.manifest.v2+json" -I -XGET https://registry.opsxlab.cn/v2/rd-mgt/threshold-admin/manifests/0.0.1 -k
HTTP/1.1 200 OK
Content-Length: 1490
Content-Type: application/vnd.docker.distribution.manifest.v2+json
Docker-Content-Digest: sha256:f9480223d5ce50f425b3ab26fb1a4c5466a6fd8ec0a09cc9e24a811c937e7b75
Docker-Distribution-Api-Version: registry/2.0
Etag: "sha256:f9480223d5ce50f425b3ab26fb1a4c5466a6fd8ec0a09cc9e24a811c937e7b75"
Date: Mon, 21 Oct 2024 02:59:38 GMT
删除镜像
- 命令行调用删除接口
上一步获取到digest后使用命令行调用如下接口:
curl -X DELETE https://registry.opsxlab.cn/v2/rd-mgt/threshold-admin/manifests/sha256:f9480223d5ce50f425b3ab26fb1a4c5466a6fd8ec0a09cc9e24a811c937e7b75 -k
在Registry URL、Image Name
和Tag
处替换实际的Registry地址、镜像名称和标签名称,例如 http://registry.example.com/v2/my-image/manifests/v1.0
注意:删除镜像对应用程序可能会产生不良影响。请确保在执行任何镜像删除操作之前,评估其对应用程序的可能影响。
如果删除失败,且返回如下内容:
扫描二维码关注公众号,回复:
17418698 查看本文章

{
“errors”:[{
“code”:“UNSUPPORTED”,“message”:“The operation is unsupported.”}]}
是由于docker registry默认不允许删除镜像。
解决办法:
在配置文件config.yml
中增加delete:enabled: true
字段
version: 0.1
log:
fields:
service: registry
storage:
cache:
layerinfo: inmemory
filesystem:
rootdirectory: /mnt/registry
delete:
enabled: true
http:
addr: :443
tls:
certificate: /etc/ssl/registry/ssl/registry.opsxlab.cn.pem
key: /etc/ssl/registry/ssl/registry.opsxlab.cn-key.pem
然后重启registry
systemctl restart registry
- 此时若删除成功,则调用
curl -X GET https://registry.opsxlab.cn/v2/rd-mgt/threshold-admin/tags/list -k
时
返回结果中tags为1.0.0
因为删除了0.0.1
,示例: