Reputation: 986
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
Upvotes: 29
Views: 33550
Reputation: 14239
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
Upvotes: 40
Reputation: 6079
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
Upvotes: 11