How to remove docker images based on name?
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')
docker rmi $(docker images --format '{{.Repository}}:{{.Tag}}' | grep 'imagename')
docker images
actually uses the first positional argument as an image name to filter for. No grep's and awk's required. The -q
option will return only the matching images IDs which can be fed to docker rmi
.
docker rmi --force $(docker images -q 'imagename' | uniq)
The uniq
is required to remove duplicates, in case you have the same image tagged differently.