Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove docker images based on name?

Tags:

docker

I want to delete all versions of docker images with names that contain a given string (imagename).
I have tried the below, but it doesn't seem to work:

docker images | grep 'imagename' | xargs -I {} docker rmi

like image 316
Aditya Singh Avatar asked Oct 11 '22 15:10

Aditya Singh


People also ask

How do I remove a docker image with tag none?

docker image prune removes all dangling images (those with tag none). docker image prune -a would also remove any images that have no container that uses them.

How do I remove docker image referenced in multiple repositories?

You cannot remove images having multiple repositories without the force modifier, see Docker docs for more info. If you use the -f flag and specify the image's short or long ID, then rmi untags and removes all images that match the specified ID.

Does docker RMI Remove from registry?

This does not remove images from a registry. You cannot remove an image of a running container unless you use the -f option. To see all images on a host use the docker image ls command.


Video Answer


2 Answers

Try the following:

docker rmi $(docker images | grep 'imagename')

or, alternatively:

docker rmi $(docker images 'completeimagename' -a -q)

In Windows PowerShell:

docker rmi $(docker images --format "{{.Repository}}:{{.Tag}}"|findstr "imagename")
like image 251
Rambler Avatar answered Oct 20 '22 08:10

Rambler


Slightly more exact version - grepping only on the repository name:

docker rmi $(docker images --format '{{.Repository}}:{{.Tag}}' | grep 'imagename')
like image 119
Elton Stoneman Avatar answered Oct 20 '22 09:10

Elton Stoneman