DEV Community

gie3d
gie3d

Posted on

Remove Docker Images according to a pattern

docker images -a | grep pattern | awk '{print $3}' | xargs docker rmi -f
Enter fullscreen mode Exit fullscreen mode

docker images -a to list all the images you have

| grep pattern will filter only the lines that contains your pattern (such as | grep node will filter images which contains node in its name)

awk '{print $3}' will extract the third column and print it out

xargs docker rmi -f will use the output of awk '{print $3}' as a parameter of docker rmi -f (which is a remove image command'

Top comments (0)