If you’ve worked with Docker long enough, you’ve probably run into this frustrating error:
docker: error creating overlay mount to ...: no space left on device
Or simply:
no space left on device
This happens when Docker consumes too much disk space—usually from unused images, stopped containers, volumes, or build cache. Luckily, Docker provides several ways to clean up your system and free up valuable storage.
In this blog post, we’ll walk through why this happens, how to identify what’s consuming space, and how to clean up Docker safely.
🚨 Why Does Docker Run Out of Disk Space?
Docker stores its data (images, containers, volumes, etc.) in the default directory:
/var/lib/docker
Over time, the following can accumulate:
- Old or unused images
- Stopped containers
- Unused or anonymous volumes
- Large build cache
- Dangling layers and networks
This can quickly fill up your disk—especially if you’re frequently building or pulling new images.
🧹 How to Clean Up Docker and Free Disk Space
✅ 1. Remove Unused Docker Objects (Images, Containers, Volumes, Networks)
The easiest and safest method:
docker system prune
This command removes:
- Stopped containers
- Unused networks
- Dangling images
- Build cache
Want to remove everything not in use?
docker system prune -a
The -a
flag also removes unused images (not just dangling ones).
⚠️ Warning: This will delete a lot—only use it if you’re sure.
✅ 2. Remove Stopped Containers
docker container prune
Removes all containers that are not running.
✅ 3. Remove Unused Volumes
Docker volumes can be large and are not removed by default.
docker volume prune
Removes all unused volumes.
✅ 4. Remove Dangling Images
“Dangling” images are layers that are no longer tagged or used.
docker image prune
Add -a
to remove all unused images:
docker image prune -a
✅ 5. Remove Build Cache (Especially After docker build
)
docker builder prune
Add -a
to remove all cache, not just dangling ones:
docker builder prune -a
🔍 Check Docker Disk Usage
Before cleaning, it’s a good idea to see what’s taking up space.
docker system df
Sample output:
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 10 3 4.5GB 3.1GB (68%)
Containers 12 1 600MB 590MB (98%)
Local Volumes 5 0 2.0GB 2.0GB (100%)
Build Cache - - 1.5GB 1.5GB
Use this to decide what to prune.
📁 Bonus: Change Docker’s Default Storage Location
If you’re running out of space on your system disk, you can move Docker’s data directory to another location:
- Create a new directory (e.g.
/mnt/docker-data
) - Edit Docker’s daemon config:
sudo nano /etc/docker/daemon.json
{
"data-root": "/mnt/docker-data"
}
- Restart Docker:
sudo systemctl restart docker
Be sure to stop Docker, move existing data, and back up before doing this on production.
📝 Conclusion
If Docker is showing a “no space left on device” error, chances are it’s due to unused resources piling up over time. With a few safe pruning commands, you can clean up gigabytes of space and restore your development workflow.
🔑 Quick Cleanup Commands:
Task | Command |
---|---|
Remove stopped containers | docker container prune |
Remove unused volumes | docker volume prune |
Remove dangling images | docker image prune |
Remove build cache | docker builder prune |
Clean all unused objects | docker system prune -a |
Check usage | docker system df |