当试图删除镜像时,Docker私有注册表不足



我试图在bash脚本中删除我的私有docker注册表mydockerregistry.com中的图像标签。身份验证是通过注册表web mydockerregistry.com:8080完成的,所以我首先使用

获得令牌
TOKEN=`curl -s 
-H "Content-Type: application/json" --user myuser:mypassword 
"http://mydockerregistry.com:8080/api/auth?service=mydockerregistry.com&scope=repository:my-repo/:*" 
| jq -r .token`

使用这个令牌,我可以浏览注册表,获得我想要删除的标记,等等。使用标签号,我使用

获得摘要
DIGEST=`curl -vk 
-H "Authorization:Bearer $TOKEN" 
-H "Accept:application/vnd.docker.distribution.manifest.v2+json" 
https://mydockerregistry.com/v2/my-repo/manifests/latest 2>&1 
|grep "< Docker-Content-Digest:" |awk '{print $3}'`

但是,当我运行

curl 
-H "Authorization:Bearer $TOKEN" 
-H "Accept:application/vnd.docker.distribution.manifest.v2+json" 
-X DELETE 
https://mydockerregistry.com/v2/my-repo/manifests/$DIGEST

我得到错误:

< HTTP/1.1 401 Unauthorized
< Content-Type: application/json; charset=utf-8
< Docker-Distribution-Api-Version: registry/2.0
< Www-Authenticate: Bearer realm="mydockerregistry.com:8080/api/auth",service="mydockerregistry.com",scope="repository:my-repo:*",error="insufficient_scope"
< X-Content-Type-Options: nosniff
< Date: Mon, 18 Oct 2021 21:29:00 GMT
< Content-Length: 160
< 
{"errors":[{"code":"UNAUTHORIZED","message":"authentication required","detail":[{"Type":"repository","Class":"","Name":"my-repo","Action":"*"}]}]}
* Connection #0 to host mydockerregistry.com left intact

我试着改变范围拉;拉,推,但我总是得到401仍然做确切的Www-Authenticate头说。

我错过了什么?

假设身份验证不是真正的问题(您可能可以在该注册表上推送和拉取),那么您启用默认禁用的删除了吗?

https://docs.docker.com/registry/configuration/删除

还要注意,一旦您删除了清单,文件系统层仍然是注册表的一部分,因此磁盘空间消耗不会下降,除非您运行垃圾收集。

https://docs.docker.com/registry/garbage-collection/

您可能会在标题上的冒号后面缺少空格(不确定curl是否会自动修复此问题),并且DELETE api不需要Accept头:

curl 
-H "Authorization: Bearer $TOKEN" 
-X DELETE 
https://mydockerregistry.com/v2/my-repo/manifests/$DIGEST

除此之外,请仔细检查您正在运行的命令中的令牌和摘要的值,然后检查注册表服务器上的日志。

好了,我终于找到问题了。

我试图运行脚本的用户有一个角色'admin',只有推和拉权限,没有*.

我创建了一个名为'delete-repo'的新角色,权限为' pull, push, * ',并将其分配给我的用户,奇迹发生了。

谢谢你的帮助!

最新更新