DEV Community

Cover image for How to free up disk space used by Docker
Isaias Velasquez
Isaias Velasquez

Posted on

How to free up disk space used by Docker

How to free up disk space used by Docker

When you use Docker on a daily basis, your disk can get full of unnamed images, stopped containers, dangling volumes and build cache. Here is how to clean all that up.

First, check how much space Docker is using:

docker system df
Enter fullscreen mode Exit fullscreen mode

This will show you images, containers, volumes and build cache with their sizes.

To remove all stopped containers, dangling images and unused networks in one go:

docker system prune -f
Enter fullscreen mode Exit fullscreen mode

If you also want to remove dangling volumes:

docker system prune -af --volumes
Enter fullscreen mode Exit fullscreen mode

Just be careful with the --volumes flag. Once they are gone, any data stored in anonymous volumes is lost.

Now if you want to remove only what is old:

docker system prune -af --filter "until=24h"
Enter fullscreen mode Exit fullscreen mode

The --filter flag removes everything created or used more than 24 hours ago.

That's all for now.
Thanks for reading!

Top comments (0)