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
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.
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.
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.
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")
Slightly more exact version - grepping only on the repository name:
docker rmi $(docker images --format '{{.Repository}}:{{.Tag}}' | grep 'imagename')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With