Complete Guide to docker system prune
Over time, Docker can fill your system with unused containers, images, networks, and volumes.
If your disk space is running low or you simply want to start fresh, cleaning up Docker can make a huge difference. In this guide, we’ll show you how to safely remove all unnecessary data using a few simple commands.
🧹 Why You Should Clean Up Docker Regularly
Every time you build an image or start a container, Docker creates layers, volumes, networks and caches. Over weeks or months, these can consume tens of gigabytes of storage. Regularly cleaning up helps you:
- Recover valuable disk space
- Remove outdated and unused images
- Fix issues with dangling containers or broken builds
- Speed up Docker operations and reduce clutter
🚀 The All-in-One Command: docker system prune
The fastest way to remove unused data is the following command:
docker system prune -a --volumes
This command will remove:
- All stopped containers
- All unused images (
-a
flag) - All unused networks
- All unused volumes (
--volumes
flag)
We made a script that helps make this interactively :
⚠️ Warning: This will delete a lot of data. Only run it if you’re sure you don’t need those containers, images, or volumes anymore.
💡 Tip: Check Disk Usage Before Cleaning
To see how much space Docker currently uses, run:
docker system df
This will give you an overview of how much space images, containers, and volumes take up.
🧩 Clean Specific Elements
If you prefer to remove only specific types of data, Docker has several targeted commands:
docker container prune
– removes stopped containersdocker image prune
– removes dangling imagesdocker volume prune
– removes unused volumesdocker network prune
– removes unused networks
🔄 When to Start from Scratch
If your Docker installation is acting weird, or you want to completely reset it, you can stop Docker and delete its data directory (on Linux):
sudo systemctl stop docker
sudo rm -rf /var/lib/docker
sudo systemctl start docker
This completely wipes your Docker environment — images, containers, networks, everything. Use with caution.
🧠 Best Practices
- Use
docker system df
weekly to monitor disk usage - Schedule
docker system prune -f
in a cron job if you run many short-lived containers - Keep important data in named volumes (so they don’t get deleted accidentally)
- Regularly update Docker to ensure cleanup commands behave correctly
✅ Conclusion
Cleaning up Docker is safe, easy, and helps your system stay fast and organized. Whether you’re a developer or sysadmin, adding a regular prune to your maintenance routine will save you time and space.