docker build: no space left on device
No space left on device during docker build
Verified against Docker 27 docs (engine/reference/commandline/system_prune), Stack Overflow #44417159 · Updated April 2026
> quick_fix
Docker's storage directory is full of old images, stopped containers, and build cache. Reclaim space with `docker system prune -af --volumes` — this usually frees several GB instantly.
# See what Docker is using
docker system df
# Reclaim everything unused (images, containers, networks, volumes, build cache)
docker system prune -af --volumes
# Just build cache (safer — keeps images)
docker builder prune -afWhat causes this error
Every docker build step creates a layer. Old layers, dangling images, exited containers, unused volumes, and the build cache all accumulate in /var/lib/docker (or the Docker Desktop VM on macOS/Windows). When the underlying filesystem fills, any disk-write during build fails.
How to fix it
- 01
step 1
Check what's using the space
`docker system df` shows a breakdown by images, containers, volumes, and build cache. Usually one of them is 10GB+.
docker system df - 02
step 2
Prune aggressively for a quick fix
`docker system prune -af --volumes` removes everything not currently in use. This is safe if you don't have critical data in unnamed volumes.
docker system prune -af --volumes - 03
step 3
On Docker Desktop (Mac/Windows), resize the VM
If prune isn't enough, Docker Desktop → Settings → Resources → Disk image size. Default is often too small for professional use.
- 04
step 4
Set up a build-cache retention policy
In docker/buildx, configure `--cache-from=type=local,dest=/tmp/.buildx-cache-new,mode=max` with a max-age to stop cache from growing unbounded.
Frequently asked questions
Is docker system prune destructive?
It removes stopped containers and unused resources. It does NOT touch running containers or the images they use. But anything you stopped without intending to delete will be gone.
Why does Docker Desktop run out of space faster than Linux Docker?
Because Docker Desktop uses a fixed-size disk image for its VM. Once that VM disk is full, even `docker pull` fails. Resize it via Settings.
How do I set a max cache size?
BuildKit supports `--cache-to=type=local,dest=... ,mode=max` with garbage collection. See docs/engine/storage-driver.