Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker registry garbage collection

Tags:

docker

Recently started to use Docker registry as a hub for corporate docker images. After couple of weeks I've found that docker registry had eaten all the disk space :(

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

Built-in garbage collector did not help: /usr/bin/docker exec registry /bin/registry garbage-collect /etc/docker/registry/config.yml. It simply does not remove unused layers and produces smth.like: 1204 blobs marked, 0 blobs eligible for deletion

We have only 1 docker image at all. But it is being pushed to registry very often. How to keep only latest version of the image?

Registry version is 2.4.0

like image 670
Dmitry Avatar asked Jul 12 '17 01:07

Dmitry


People also ask

What is Docker garbage collection?

In the context of the Docker registry, garbage collection is the process of removing blobs from the filesystem when they are no longer referenced by a manifest. Blobs can include both layers and manifests. Registry data can occupy considerable amounts of disk space.

Does Docker registry contain collection of repositories?

A Docker registry is a service that hosts and distributes Docker images. In many cases, a registry will consist of multiple repositories which contain images related to a specific project. Within a given repository tags are used to differentiate between versions of an image (e.g. ubuntu/httpd:version2.

Does Docker registry contain image collection?

A registry is a storage and content delivery system, holding named Docker images, available in different tagged versions. Example: the image distribution/registry , with tags 2.0 and 2.1 . Users interact with a registry by using docker push and pull commands.

What is stored in Docker registry?

A Docker registry is organized into Docker repositories , where a repository holds all the versions of a specific image. The registry allows Docker users to pull images locally, as well as push new images to the registry (given adequate access permissions when applicable).


2 Answers

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

I also couldn't find any mention of that flag in the Docker Registry documentation, I found it in a GitHub thread.

According to the source code the short form is -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

EDIT: The -m (--delete-untagged) option is still buggy with multi-arch manifests: https://github.com/distribution/distribution/issues/3178

like image 57
Daniel F Avatar answered Sep 18 '22 16:09

Daniel F


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:

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

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

like image 35
Ricardo Branco Avatar answered Sep 19 '22 16:09

Ricardo Branco