How can I delete a docker images by their tag <none> and repository name?

Viewed 1124

I would like to ask if it's possible to delete docker images for its tag or the created label, I have something like this:

Repository                     TAG             IMAGE_ID       CREATED          SIZE

registry.someRegistry.         latest          fa8767676       5 hours ago     119MB
registry.someRegistry.         <none>          878787874       29 hours ago    119MB
registry.someRegistry.         <none>          jkj7jjjk4       2 days ago      119MB
registry.someRegistry.         <none>          d99090iii       3 days ago      119MB

I need to remove all the images but not the most recently one in this case is the one tagged with latest or the one with the most recent Created date. I can use the next command to delete all the images until 5 hours of creation, but it's not appropriate, because I could delete more images not just the last one, would be better to delete images by the tag=latest.

docker image prune -a --force --filter "until=5h"

I need also an additional filter for the registry I think, in order to remove just the images for the registry I need.

Any good way to achieve that?

3 Answers

The simplest would be the rmi command, i.e.:

docker rmi 878787874

This is a "remove image" command and uses the IMAGE_ID you list.

None of the replies were helpful, and there does not seem to be another thread either. It is way too late but I had the same problem and found this solution:

docker rmi $(docker images | grep "<none>" | grep "registry.someRegistry." | awk {'print $3'})

This is not 100% proof because grep looks for a string in the name and the tag, so theoretically if your registry name appears in some tag and vice versa you could accidentally delete it.

you can remove dangling images with filter

 docker images --filter dangling=true
Related