如何从私有 docker 注册表中删除图像? [英] How to delete images from a private docker registry?

查看:38
本文介绍了如何从私有 docker 注册表中删除图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行一个私有 docker 注册表,我想从存储库中删除除 latest 之外的所有图像.我不想删除整个存储库,只想删除其中的一些图像.API 文档 没有提到这样做的方法,但肯定有可能吗?

I run a private docker registry, and I want to delete all images but the latest from a repository. I don't want to delete the entire repository, just some of the images inside it. The API docs don't mention a way to do this, but surely it's possible?

推荐答案

目前您不能将 Registry API 用于该任务.它只允许您删除存储库或特定标签.

Currently you cannot use the Registry API for that task. It only allows you to delete a repository or a specific tag.

一般来说,删除仓库意味着删除与该仓库关联的所有标签.

In general, deleting a repository means, that all the tags associated to this repo are deleted.

删除标签意味着删除图像和标签之间的关联.

Deleting a tag means, that the association between an image and a tag is deleted.

以上都不会删除单个图像.它们留在您的磁盘上.

None of the above will delete a single image. They are left on your disk.

对于此解决方法,您需要将 docker 图像存储在本地.

您的解决方案的一种变通方法是删除除最新标签之外的所有标签,从而可能删除对相关图像的引用.然后你可以运行这个脚本来删除所有图片,不是由任何标签或任何使用图像的祖先引用.

A workaround for your solution would be to delete all but the latest tags and thereby potentially removing the reference to the associated images. Then you can run this script to remove all images, that are not referenced by any tag or the ancestry of any used image.

考虑这样的图像图,其中大写字母 (A, B, ...) 表示短图像 ID 和 <- 表示一个图像基于另一个图像:

Consider an image graph like this where the capital letters (A, B, ...) represent short image IDs and <- means that an image is based on another image:

 A <- B <- C <- D

现在我们给图片添加标签:

Now we add tags to the picture:

 A <- B <- C <- D
           |    |
           |    <version2>
           <version1>

这里,标签引用图像C,标签引用图像D.

Here, the tag <version1> references the image C and the tag <version2> references the image D.

在你的问题中,你说你想删除

In your question you said that you wanted to remove

所有图片,但最新

.现在,这个术语不太正确.您混合了图像和标签.看看图表,我想你会同意标签 代表最新版本.事实上,根据这个问题你可以有代表最新版本的标签:

. Now, this terminology is not quite correct. You've mixed images and tags. Looking at the graph I think you would agree that the tag <version2> represents the latest version. In fact, according to this question you can have a tag that represents the latest version:

 A <- B <- C <- D
           |    |
           |    <version2>
           |    <latest>
           <version1>

既然<latest> 标签引用了图像D 我问你:你真的想删除除了图像D 之外的所有内容吗?可能不会!

Since the <latest> tag references image D I ask you: do you really want to delete all but image D? Probably not!

如果您使用 Docker REST API 删除标签 ,您将得到:

If you delete the tag <version1> using the Docker REST API you will get this:

 A <- B <- C <- D
                |
                <version2>
                <latest>

记住: Docker 永远不会删除图像!即使删除了,在这种情况下它也不能删除图像,因为图像 C 是被标记的图像 D 的祖先的一部分.

Remember: Docker will never delete an image! Even if it did, in this case it cannot delete an image, since the image C is part of the ancestry for the image D which is tagged.

即使您使用这个脚本,也不会出现任何图像已删除.

Even if you use this script, no image will be deleted.

在您可以控制某人何时可以拉取或推送到您的注册表的条件下(例如,通过禁用 REST 接口).如果没有其他图像基于该图像并且没有标记引用该图像,您可以从图像图中删除该图像.

Under the condition that you can control when somebody can pull or push to your registry (e.g. by disabling the REST interface). You can delete an image from an image graph if no other image is based on it and no tag refers to it.

注意在下图中,图像D不是基于C,而是基于B.因此,D 不依赖于 C.如果删除此图中的标签 ,则任何图像都不会使用图像 C这个脚本可以删除它.

Notice that in the following graph, the image D is not based on C but on B. Therefore, D doesn't depend on C. If you delete tag <version1> in this graph, the image C will not be used by any image and this script can remove it.

 A <- B <--------- D
                  |
                  <version2>
                  <latest>
          <- C
              |
              <version1>

清理后,您的图像图如下所示:

After the cleanup your image graph looks like this:

 A <- B <- D
           |
           <version2>
           <latest>

这是你想要的吗?

这篇关于如何从私有 docker 注册表中删除图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆