The blog about containerisation, virtual machines and useful shell snippets and findings

Oneliner how to remove last 5 stopped docker containers

This oneliner will query for last 5 containers and removes them.

docker ps -a -n 5 -q | xargs docker rm

It is useful when you have dangling containers after failed builds

Afterward, you can launch image cleanup because you won’t be tied with stopped containers.

docker rmi `docker images -qf dangling=true`