Docker: Cleaning up after yourself

I’ve been doing a lot of work with Docker of late mostly for creating easy dev and test environments. One of the problems you come across when doing this, is that you land up with all sorts of orphaned images and containers which chew up disk space and systems resources.

The following commands will give you a clean slate. Stopping all running containers, removing them and deleting any images.

docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
docker rmi $(docker images -q)

Obviously take care when running these commands, you don’t want to nuke something important :)