Remove Docker images no more used

Posted by ZedTuX 0n R00t on November 29, 2014

How to go from the following:

to:

easily ?

Just run the following commands (and ignore the warnings and errors …):

1
2
$ docker ps -a -q --filter "status=exited" | xargs docker rm
$ docker rmi `docker images --filter "dangling=true" | awk '{ print $3 }' | grep -v IMAGE`

The magic here is the --filter flag of docker which allows us to filter the existing images and select only the one which are in status exited (so no running).