You cannot currently use the Registry API for this task. This allows you to delete the repository or specific tag.
Typically, deleting a repository means that all tags associated with this repo are deleted.
Removing a tag means that the link between the image and the tag is removed.
None of the above will delete a single image. They are left on your disk.
Bypass
For this workaround, you need to save your docker files.
A workaround for your solution would be to remove all but the latest tags, and thus the ability to remove links to related images. You can then run this script to remove all images that are not referenced by tags or ancestors of any image used.
Terminology (images and tags)
Consider an image graph like this, where the capital letters ( A , B , ...) are short image identifiers, and <- means that the image is based on another image:
A <- B <- C <- D
Now we add tags to the image:
A <- B <- C <- D | | | <version2> <version1>
Here, the <version1> refers to image C , and the <version2> refers to image D
Clarification of your question
In your question, you said you want to delete
all images but latest
. Now this terminology is not entirely correct. You have mixed images and tags. Looking at the graph, I think you will agree that the <version2> is the latest version. In fact, according to this question , you can have a tag that represents the latest version:
A <- B <- C <- D | | | <version2> | <latest> <version1>
Since the <latest> refers to image D , I ask you: do you really want to delete everything except image D ? Probably not!
What happens if you remove the tag?
If you remove the <version1> tag using the Docker REST API, you will get the following:
A <- B <- C <- D | <version2> <latest>
Remember: Docker will never delete an image! Even if this happened, in this case he cannot delete the image, since the image C is part of the ancestor for the image D that is marked.
Even if you use this script , the image will not be deleted.
When the image can be deleted
Provided that you can control when someone can pull or click on your registry (for example, by disabling the REST interface). You can remove an image from a graphic image if there is no other image on it, and none of them refers to it.
Note that in the following graph, the image of D not based on C , but on B Therefore, D is independent of C If you remove the <version1> in this graph, the C image will not be used by any image and this script can remove it.
A <- B <--------- D \ | \ <version2> \ <latest> \ <- C | <version1>
After cleaning, your graph graph looks like this:
A <- B <- D | <version2> <latest>
Is this what you want?