I run a private docker registry, and I want to delete all images but the latest
from a repository. I don't want to delete the entire repository, just some of the images inside it. The API docs don't mention a way to do this, but surely it's possible?
相关问题
- Docker task in Azure devops won't accept "$(pw
- Unable to run mariadb when mount volume
- Unspecified error (0x80004005) while running a Doc
- What would prevent code running in a Docker contai
- How to reload apache in php-apache docker containe
This docker image includes a bash script that can be used to remove images from a remote v2 registry : https://hub.docker.com/r/vidarl/remove_image_from_registry/
Simple ruby script based on this answer: registry_cleaner.
You can run it on local machine:
./registry_cleaner.rb --host=https://registry.exmpl.com --repository=name --tags_count=4
And then on the registry machine remove blobs with
/bin/registry garbage-collect /etc/docker/registry/config.yml
.Problem 1
You mentioned it was your private docker registry, so you probably need to check Registry API instead of Hub registry API doc, which is the link you provided.
Problem 2
docker registry API is a client/server protocol, it is up to the server's implementation on whether to remove the images in the back-end. (I guess)
Detail explanation
Below I demo how it works now from your description as my understanding for your questions.
You run you run private docker registry, I use the default one and listen in
5000
portThen I tag the local image and push into it.
After that you can use Registry API to check it exists in your private docker registry
Now I can delete the tag using that API !!
Check again, the tag doesn't exist in your private registry server
There are some clients (in Python, Ruby, etc) which do exactly that. For my taste, it isn't sustainable to install a runtime (e.g. Python) on my registry server, just to housekeep my registry!
So
deckschrubber
is my solution:images older than a given age are automatically deleted. Age can be specified using
-year
,-month
,-day
, or a combination of them:UPDATE: here's a short introduction on deckschrubber.
This is really ugly but it works, text is tested on registry:2.5.1. I did not manage to get delete working smoothly even after updating configuration to enable delete. The ID was really difficult to retrieve, had to login to get it, maybe some misunderstanding. Anyway, the following works:
Login to the container
Define variables matching your container and container version:
Move to the the registry directory:
Delete files related to your hash:
Delete manifests:
Logout
Run the GC:
If all was done properly some information about deleted blobs is shown.
Below Bash Script Deletes all the tags located in registry except the latest.
After this Run