Cleaning up the docker registry

Working on my docker swarm recently I noticed that my storage was running low. After investigation, I found I had 17GB of usage by my docker registry. I have no need to have that many versions of my custom built containers on hand, so I went through the process of cleaning it up.

I started out by trying this, but it only marked 8 images for deletion.

administrator@bot-docker-01:/mnt/administration/Bash-Scripts/Docker-Compose/port-dev$ docker exec 355b5721ae5f /bin/registry garbage-collect /etc/docker/registry/config.yml

After some additional research I managed to find out about this command. Running it netted me a few thousand images marked for deletion.

administrator@bot-docker-01:/mnt/administration/Bash-Scripts/Docker-Compose/port-dev$ docker exec -it -u root 355b5721ae5f bin/registry garbage-collect --delete-untagged /etc/docker/registry/config.yml

The container name is randomized from the swarm stack so that’s a bit odd. I used docker ps to get the name.

With that command finally working to clear out the old versions, my container registry data usage dropped SIGNIFICANTLY. This is exactly what I was hoping for so that my gluster storage array would have a bit more free space.


This stack overflow thread

Contents Below:

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:

EDIT: The -m (--delete-untagged) option is still buggy with multi-arch manifests:


Something that could be interesting to use in the future would be this:

It may let me automate the whole cleanup process.

Leave a Reply