I want to prune images based on image/repo name , lets say i have unused images named after postgres, postgres:v2, nginx and nginx:v2 now i want to prune all images based on image name that is postgres not nginx
docker image prune -a -f | grep postgres
but pruning all images i.e postgres and nginx , Thanks in advance
2
Answers
There are probably multiple ways to do it, but I have a defined function that accepts a string as an argument, and deletes all images that have this partial string in their name:
Then you can do:
In reality, I am using a bash alias manager (that I developed, full disclosure) and have many aliases for docker, so I can do things like:
Here is how I define the
d rmi
function, along with other useful functions.docker image prune
doesn’t support passing the image name with the command.You can use the
docker rmi
command instead on the output ofdocker images
command to delete specific docker images: