We updated our private docker registry to the official Registry 2.0. This version can now delete docker images identified by a hashtag (see https://docs.docker.com/registry/spec/api/#deleting-an-image) but I still don't see a way to cleanup old images.
As our CI server is continously producing new images, I would need a method to delete all images from the private registry which are no longer identified by a named tag.
If there's no built-in way to achieve this, I think a custom script could possibly work, but I don't see a v2 API method either to list all stored hashtags of an image..
How can I keep my private registry clean? Any hints?
Deletion of images (you can keep 10 last versions, like I do in my CI) is done in three steps:
Enable image deletion by setting environment variable REGISTRY_STORAGE_DELETE_ENABLED: "true"
and passing it to docker-registry
Run below script (it will delete all images and tags but keep last 10 versions)
registry.py -l user:pass -r https://example.com:5000 --delete --num 10
Run garbage collection (you can put it into your daily cron task)
docker-compose -f [path_to_your_docker_compose_file] run registry bin/registry garbage-collect /etc/docker/registry/config.yml
registry.py can be downloaded from the link below, it also allows listing images, tags and layers, as well as deleting a particular image and/or tag.
https://github.com/andrey-pohilko/registry-cli
Before garbage collection my registry folder was 7 Gb, after I ran the above steps it deflated down to 1 Gb.