After you have worked with Docker for a while, you will notice that it eats disk space like a whale. This is especially true for build servers like Jenkins, where Docker images are often created for every code commit.

Docker by default stores every image you build, every container you run and every volume you create. They are stored until you explicitly delete them. Therefore it’s important to do a bit of housekeeping every now and then.

The one command to rule them all

This command will delete all stopped containers, all networks not used by at least one container, all images and all build cache:

docker system prune -a

Note that this command was introduced in Docker version 1.13.

Pro tip: Add the -f argument to skip asking for confirmation.

About the author

Miiro

Miiro Juuso works as Head of DevOps at AND Digital. Reach Miiro at mjuuso@and.digital