Quick Answer
# Remove stopped containers, unused networks, and dangling images
docker system prune
# Remove everything including all unused images and volumes (use with caution)
docker system prune -a --volumes
What You’re Trying to Do
After prolonged Docker usage, stopped containers and unused images accumulate and eat up disk space. Running df -h and finding almost no free space is a common trigger for reaching for docker system prune. This guide covers every option and shows you exactly what gets deleted.
Environment
- OS: Ubuntu 22.04 / macOS Ventura
- Docker: 24.x or later
Solution
Basic Usage
docker system prune
This removes:
- Stopped containers (status:
Exited) - Networks not used by any container
- Dangling images (untagged, unreferenced)
- Build cache
To skip the confirmation prompt:
docker system prune -f
Remove All Unused Images
docker system prune -a
The -a / --all flag extends deletion to all images not referenced by any container — not just dangling ones. Useful for reclaiming large amounts of disk space in development environments.
Include Volumes
docker system prune -a --volumes
Warning: --volumes also deletes named volumes, which may contain database data or other persistent state. Verify what volumes exist before running this.
Preview What Will Be Deleted
# List stopped containers
docker ps -a --filter "status=exited"
# List dangling images
docker images -f "dangling=true"
# List volumes
docker volume ls
Check Disk Usage After Pruning
docker system df
| Type | SIZE | RECLAIMABLE |
|---|---|---|
| Images | 3.2GB | 1.1GB |
| Containers | 0B | 0B |
| Volumes | 500MB | 200MB |
| Build Cache | 800MB | 800MB |
The RECLAIMABLE column shows how much space you can actually recover.
Common Errors
Error response from daemon: conflict
Resources in use by running containers are skipped, not deleted. This is expected behavior — not an error.
permission denied
sudo docker system prune
On Linux, if your user isn’t in the docker group, you’ll need sudo.
Accidentally Deleted a Volume
If you ran --volumes and lost data without a backup, recovery is extremely difficult. Always run docker volume inspect <name> to check the mount path and back up important data to the host before pruning.
FAQ
Q: Will running containers be affected?
No. docker system prune only targets stopped resources. Running containers, the images they use, and their volumes are left untouched.
Q: What’s the difference between docker image prune and docker system prune?
docker image prune removes only images. docker system prune also removes stopped containers, unused networks, and build cache — a broader sweep in a single command.
Q: Can I automate this on a schedule? Yes — add it to cron:
# Run every Sunday at 1 AM (no confirmation prompt)
0 1 * * 0 docker system prune -f >> /var/log/docker-prune.log 2>&1
Q: How do I remove only the build cache?
docker builder prune
This removes the build cache without touching containers or images.
Q: What’s the difference between using -a and not using it?
Without -a, only dangling images (untagged) are removed. With -a, all images not referenced by any container are removed — including images you pulled but haven’t run yet. Be careful with -a in shared environments.
Q: Does this work on Windows with Docker Desktop? Yes. Run the same commands from PowerShell or a WSL2 terminal.
Related Articles
- docker image cleanup — Remove Unused Docker Images
- docker logs — View Container Logs
- Docker Volume Basics — Persist Data in Containers
- Docker Network Basics — Understand Container Networking
Recommended VPS / Hosting
Looking to run Docker in production? These services are solid choices: