Docker registry garbage collection
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
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