删除远程 docker 注册表上的 docker 存储库

Jam*_*979 9 docker docker-registry

给定管理多个 docker 存储库的 docker 注册表,如何删除其中一个存储库?

鉴于库repo1repo2repo3

$ curl -X GET localhost:5000/v2/_catalog
{"repositories":["repo1", "repo2", "repo3"]}
Run Code Online (Sandbox Code Playgroud)

我想删除存储库repo1所以_catalog没有列出repo1,比如

$ curl -X GET localhost:5000/v2/_catalog
{"repositories":["repo2", "repo3"]}
Run Code Online (Sandbox Code Playgroud)

目前,存储库repo1只有默认的"latest"图像标签

$ curl -X GET localhost:5000/v2/repo1/tags/list
{"name":"repo1","tags":["latest"]}
Run Code Online (Sandbox Code Playgroud)

(也许这会影响能够删除repo1?)



我试过了...

返回以下命令404 page not found

$ curl -X DELETE localhost:5000/v1/repositories/repo1
$ curl -X DELETE localhost:5000/v2/repositories/repo1
$ curl -X DELETE localhost:5000/v2/repo1
Run Code Online (Sandbox Code Playgroud)

以下返回 {"errors":[{"code":"UNSUPPORTED","message":"The operation is unsupported."}]}

$ curl -X DELETE localhost:5000/v2/repo1/manifests/latest
Run Code Online (Sandbox Code Playgroud)

使用

远程 docker-registry 是 registry/2.0

curl -vX GET localhost:5000/v2/
< HTTP/1.1 200 OK
...
< Docker-Distribution-Api-Version: registry/2.0
...
Run Code Online (Sandbox Code Playgroud)

$ /bin/registry github.com/docker/distribution v2.4.1
Run Code Online (Sandbox Code Playgroud)

Neg*_*iri 18

通过启用 DELETE API,您只能从v2/_catalog.

为此,您应该:


1.启用删除API:

1.1 由config.ymlstorage.delete.enabled:true

1.2 环境: -e REGISTRY_STORAGE_DELETE_ENABLED=true

2.通过GET /v2/<name>/manifests/<tag> (不要忘记有 Header Accept: application/vnd.docker.distribution.manifest.v2+json获取标签引用

在响应头中,你有 docker-content-digest: <sha256:xxx>

3.发送 DELETE /v2/<name>/manifests/<sha256:xxx>

4. 运行垃圾收集器: bin/registry garbage-collect /etc/docker/registry/config.yml

5.删除文件: rm -r /var/lib/registry/docker/registry/v2/repositories/<name>/<tag>


最后:现在你可以看到

curl -X GET localhost:5000/v2/_catalog {"repositories":["repo2", "repo3"]}



附:

5的后果:https : //github.com/docker/distribution/issues/2983#issuecomment-530251232

  • 请注意,这**不会删除单个标签**,因为多个标签可以引用摘要识别的一张图像。 (2认同)

BMi*_*tch 6

There is no API to delete a repository. You need to delete individual tags or manifests within the repository. And until OCI's distribution-spec, there wasn't even an API to delete tags, you need to delete image manifests by digest, which deletes all tags pointing to that same digest.

To delete manifests, first ensure that you have enabled deletion according to this documentation before attempting anything. In your configuration of the registry, you would add the following section:

delete:
  enabled: true
Run Code Online (Sandbox Code Playgroud)

That can also be set by starting your registry container with the REGISTRY_STORAGE_DELETE_ENABLED=true environment variable specified.

Then you can call the manifest delete API:

curl -X DELETE \
     -s "https://registry.example.org/v2/${repo}/manifests/${sha}"
Run Code Online (Sandbox Code Playgroud)

如果您想要一个围绕此的包装器来处理身份验证,甚至支持标记删除,请参阅我编写的regclient 的 regctl CLI。Google 的crane 和RedHat 的skopeo 也可能提供此功能。

删除清单后,您仍然需要通过垃圾收集来清理清单指向的其他项目(这需要在没有写入发生时完成):

docker exec registry /bin/registry garbage-collect /etc/docker/registry/config.yml --delete-untagged
Run Code Online (Sandbox Code Playgroud)

也就是说,您仍然会达到存储库本身未被删除的程度。您可以从注册表的文件系统中删除整个目录。但我建议从项目中获得对此实施的支持。有关将功能添加到官方注册表映像的更多详细信息,请参阅此问题。