Docker registry garbage collection

Recently started using Docker registry as a hub for corporate docker images. After a couple of weeks I found that the docker registry wiped out all disk space :(

We have an automatic deployment for developers that pulls the last master from GIT every time, then builds a docker image and pushes it into our registry. Image title and image tag are always the same. So I was expecting the old image to be overwritten with the new one in the docker registry , but in reality all these layers are going to be collected in the ... / docker / registry / v2 / blobs / sha256 / folder .

The built in garbage collector didn't help: / usr / bin / docker exec registry / bin / registry garbage-collect / etc / docker / registry / config.yml . It just doesn't remove unused layers and produces smth.like: 1204 marks marked with 0 blobs to remove

We only have 1 docker image. But it is often inserted into the registry. How do I keep only the latest version of an image?

Registry version - 2.4.0

+9


source to share


2 answers


To force the garbage collector to remove untagged images, some manifest files must be removed. I have a script that I am using in a production environment with Docker Registry 2.4.0 and still works with 2.6.1:

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



UPDATE: I rewrote it in Python and created a Docker image: https://github.com/ricardobranco777/clean_registry

+5


source


As of Docker Registry 2.7.0 (current as of 2019-09-18 - 2.7.1) there is a flag --delete-untagged

that removes these unrelated blobs

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. Any empty blob and repository directories will still remain.



I also couldn't find any mention of this flag in the Docker Registry documentation, I found it on the GitHub branch.

According to the source code , the short form is -m

.

Here is the pull request: https://github.com/docker/distribution/pull/2302

0


source







All Articles