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
Currently you cannot use the Registry API for that task. It only allows you to delete a repository or a specific tag.
In general, deleting a repository means, that all the tags associated to this repo are deleted.
Deleting a tag means, that the association between an image and a tag is deleted.
None of the above will delete a single image. They are left on your disk.
Workaround
For this workaround you need to have your docker images stored locally.
A workaround for your solution would be to delete all but the latest tags and thereby potentially removing the reference to the associated images. Then you can run this script to remove all images, that are not referenced by any tag or the ancestry of any used image.
Terminology (images and tags)
Consider an image graph like this where the capital letters (
A
,B
, ...) represent short image IDs and<-
means that an image is based on another image:Now we add tags to the picture:
Here, the tag
<version1>
references the imageC
and the tag<version2>
references the imageD
.Refining your question
In your question you said that you wanted to remove
. Now, this terminology is not quite correct. You've mixed images and tags. Looking at the graph I think you would agree that the tag
<version2>
represents the latest version. In fact, according to this question you can have a tag that represents the latest version:Since the
<latest>
tag references imageD
I ask you: do you really want to delete all but imageD
? Probably not!What happens if you delete a tag?
If you delete the tag
<version1>
using the Docker REST API you will get this:Remember: Docker will never delete an image! Even if it did, in this case it cannot delete an image, since the image
C
is part of the ancestry for the imageD
which is tagged.Even if you use this script, no image will be deleted.
When an image can be deleted
Under the condition that you can control when somebody can pull or push to your registry (e.g. by disabling the REST interface). You can delete an image from an image graph if no other image is based on it and no tag refers to it.
Notice that in the following graph, the image
D
is not based onC
but onB
. Therefore,D
doesn't depend onC
. If you delete tag<version1>
in this graph, the imageC
will not be used by any image and this script can remove it.After the cleanup your image graph looks like this:
Is this what you want?
Briefly;
1) You must typed following command for RepoDigests of a docker repo;
2) Use registry REST API
You should get a 202 Accepted for a successful invocation.
3-) Run Garbage Collector
registry — registry container name.
For more detail explanation enter link description here
I've faced same problem with my registry then i tried the solution listed below from a blog page. It works.
Step 1: Listing catalogs
You can list your catalogs by calling this url:
Response will be in the following format:
Step 2: Listing tags for related catalog
You can list tags of your catalog by calling this url:
Response will be in the following format:
}
Step 3: List manifest value for related tag
You can run this command in docker registry container:
Response will be in the following format:
Run the command given below with manifest value:
Step 4: Delete marked manifests
Run this command in your docker registy container:
Here is my config.yml
The current
v2
registry now supports deleting viaDELETE /v2/<name>/manifests/<reference>
See: https://github.com/docker/distribution/blob/master/docs/spec/api.md#deleting-an-image
Working usage: https://github.com/byrnedo/docker-reg-tool
Edit: The manifest
<reference>
above can be retrieved from requesting toGET /v2/<name>/manifests/<tag>
and checking
Docker-Content-Digest
header in the response.