Removing Docker containers that have exited

Problem

You would like to clear Docker containers that have been exited and not cleared properly.

Solution

Run the following to find out the containers that have exited and remove them.

sudo docker ps -a | grep 'Exited' | tail -n +1 | awk '{ print $1 }' | xargs sudo docker rm