简体   繁体   English

Docker 注册表垃圾收集

[英]Docker registry garbage collection

Recently started to use Docker registry as a hub for corporate docker images.最近开始使用 Docker 注册表作为企业 Docker 镜像的中心。 After couple of weeks I've found that docker registry had eaten all the disk space :(几周后,我发现 docker 注册表已经吃光了所有的磁盘空间:(

We have an automatic deploy for the developers which every time pulls latest master from GIT, then creates docker image and pushes it to our registry.我们为开发人员提供了一个自动部署,每次从 GIT 中提取最新的 master,然后创建 docker 镜像并将其推送到我们的注册表。 Image name and image tag are always the same.图像名称和图像标签始终相同。 So I've expected the old image to be overwritten by new one at docker registry, but actually all these layers are being collected at .../docker/registry/v2/blobs/sha256/ folder.所以我预计旧镜像会被 docker 注册表中的新镜像覆盖,但实际上所有这些层都被收集在.../docker/registry/v2/blobs/sha256/文件夹中。

Built-in garbage collector did not help: /usr/bin/docker exec registry /bin/registry garbage-collect /etc/docker/registry/config.yml .内置垃圾收集器没有帮助: /usr/bin/docker exec registry /bin/registry 垃圾收集 /etc/docker/registry/config.yml It simply does not remove unused layers and produces smth.like: 1204 blobs marked, 0 blobs eligible for deletion它只是不会删除未使用的层并产生 smth.like:标记 1204 个 blob,0 个 blob 符合删除条件

We have only 1 docker image at all.我们只有 1 个 docker 镜像。 But it is being pushed to registry very often.但它经常被推送到注册表。 How to keep only latest version of the image?如何只保留最新版本的图像?

Registry version is 2.4.0注册表版本是 2.4.0

Since Docker Registry 2.7.0 (current as of 2019-09-18 is 2.7.1) there is a flag --delete-untagged which removes those unreferenced blobs由于 Docker Registry 2.7.0(截至 2019 年 9 月 18 日为 2.7.1),有一个标志--delete-untagged可以删除那些未引用的 blob

docker exec -it -u root registry bin/registry garbage-collect --delete-untagged /etc/docker/registry/config.yml

It doesn't get rid of empty directories, though.但是,它并没有摆脱空目录。 All the empty blob and repository directories will still remain.所有空的 blob 和存储库目录仍将保留。

I also couldn't find any mention of that flag in the Docker Registry documentation, I found it in a GitHub thread.我在 Docker Registry 文档中也找不到任何提及该标志的内容,我在 GitHub 线程中找到了它。

According to the source code the short form is -m .根据源代码,简短形式是-m

GCCmd.Flags().BoolVarP(&removeUntagged, "delete-untagged", "m", false, "delete manifests that are not currently referenced via tag")

Here is the pull request: https://github.com/docker/distribution/pull/2302这是拉取请求: https : //github.com/docker/distribution/pull/2302

EDIT: The -m ( --delete-untagged ) option is still buggy with multi-arch manifests: https://github.com/distribution/distribution/issues/3178编辑: -m--delete-untagged )选项仍然存在多架构清单的问题: https : //github.com/distribution/distribution/issues/3178

To force the garbage collector to remove the untagged images, some manifest files must be removed.要强制垃圾收集器删除未标记的图像,必须删除一些清单文件。 I have a script that I have been using in production since Docker Registry 2.4.0 and still works with 2.6.1:我有一个自 Docker Registry 2.4.0 以来一直在生产中使用的脚本,并且仍然适用于 2.6.1:

https://github.com/ricardobranco777/clean_registry.sh https://github.com/ricardobranco777/clean_registry.sh

EDIT: I rewrote it in Python and created a Docker image: https://github.com/ricardobranco777/clean_registry编辑:我用 Python 重写它并创建了一个 Docker 映像: https : //github.com/ricardobranco777/clean_registry

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM