从私人Docker注册表中删除图像 [英] Deleting images from a private docker registry

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

问题描述

我运行一个私人的docker注册表,我想从存储库中删除所有图像,但是最新的最新的。我不想删除整个存储库,只是其中的一些图像。 API文档没有提到这样做的方法,但是

解决方案

目前,您无法使用Registry API进行该任务。它只允许您删除存储库或特定的标签。



通常,删除存储库意味着与该repo关联的所有标签都将被删除。



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



以上都不会删除一张图片。他们留在你的磁盘上。






解决方法



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



解决方案的解决方法是删除除最新标签之外的所有内容,从而可能删除对相关图像的引用。然后,您可以运行 此脚本 以删除所有图像,即



术语(图像和标签)



考虑大写字母( A B ,...)的图像图像代表短图像ID和 < - 意味着图像基于另一个图像:

  A <  -  B<  -  C<  -  D 

现在我们在图片中添加标签: / p>

  A<  -  B<  -   -  C  -  D 
| |
| <版本2>
< version1>

这里,标签< version1> 引用图像 C 和标签< version2> 引用图像 D



优化你的问题



在你的问题中你说你想删除< 最新


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

  A<  -  B<  -  C<  -  D 
| |
| <版本2>
| <最新>
< version1>

由于< latest> 标签引用图像 D 我问你:你真的想删除所有图像 D ?可能不是!



如果删除标签会发生什么?



如果您删除标签< version1> 使用Docker REST API,您将获得以下信息:

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

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



即使你使用 这个脚本 ,没有图片将被删除。



图像可以被删除



在您可以控制何时可以拉或推送到您的注册表(例如通过禁用REST界面)的条件下。如果没有其他图像是基于图像,则可以从图像图像中删除图像,并且没有标签引用。请注意,在下图中, D 的图像基于 C 而是 B 。因此, D 不依赖于 C 。如果您在此图表中删除标签< version1> ,则图像 C 不会被任何图像和 此脚本 可以将其删除。

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

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

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

这是你想要的吗?


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?

解决方案

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.


Workaround

For this workaround you need to have your docker images stored locally.

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.

Terminology (images and tags)

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>

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

Refining your question

In your question you said that you wanted to remove

all images but the latest

. 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>

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

What happens if you delete a tag?

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

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

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.

When an image can be deleted

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.

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>

Is this what you want?

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

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