Cleaning Exited Docker

docker ps -a (so many Exited containers)

Posted by Kaushik Raj on October 23, 2015

I tend to run docker containers in interactive terminal mode. Over time, this causes tonnes of zombie containers (docker ps -a). Removing all those Exited containers is a pain.

The following single line command allows to remove all Exited containers.

    
$docker ps -a | grep Exited | awk '{print $1}' | xargs --no-run-if-empty docker rm
    

If you need to run docker in sudo mode, following is the command for that.

    
$sudo docker ps -a | grep Exited | awk '{print $1}' | xargs --no-run-if-empty sudo docker rm
    

Kill one, Kill All!!