Last Updated: February 25, 2016
·
695
· martinisoft

Remove stopped Docker containers

You could remove all Docker containers like this:

docker rm $(docker ps -a -q)

Note: This will not only remove stopped, but ALL containers. The -a flag returns all containers while the -q flag gives only container IDs.

The better way would be to pipe the output to xargs to not execute a subshell:

docker ps -a -q | xargs docker rm

Want to remove more than 1 day old containers?

docker ps -a | grep 'days old' | awk '{print $1}' | xargs docker rm