docker build: "write error: no space left on device"
By Daniel Zoghalchali·Latchkey
A docker build aborted because writing a layer hit ENOSPC. Each instruction can add a layer, and the build cache plus base images quickly fill a small runner disk.
What this error means
The build fails part-way through with write error: no space left on device, usually during a RUN, COPY, or layer export. A fresh runner or a prune clears it without any Dockerfile change.
docker
=> ERROR [build 6/9] RUN npm ci
write /var/lib/docker/tmp/buildkit-...: no space left on device
##[error] buildx failed with: ERROR: failed to solve: no space left on device
Common causes
The build cache and image layers filled /var/lib/docker
BuildKit keeps a layer cache and intermediate state. Across jobs on a reused runner this grows until the docker data root is full.
Large base images or build context
A multi-GB base image or an unfiltered build context (missing .dockerignore) can exhaust the disk in a single build.
How to fix it
Prune docker data and shrink the context
Reclaim layer cache and dangling state, then trim what gets sent to the daemon.
shell
docker system df
docker builder prune --all --force
docker system prune --all --force --volumes
Reduce what each build writes
Add a .dockerignore to keep node_modules, .git, and artifacts out of the build context.
Use multi-stage builds so only the final stage ships.
Run image-heavy builds on a runner with a larger disk.
How to prevent it
Prune the builder cache between heavy builds.
Keep base images lean and pin them.
Right-size disk for runners that build large images.
Frequently asked questions
What causes "docker build out of disk"?
BuildKit keeps a layer cache and intermediate state. Across jobs on a reused runner this grows until the docker data root is full.
How do I fix docker build out of disk?
Reclaim layer cache and dangling state, then trim what gets sent to the daemon.
Can Latchkey fix this automatically?
Yes. Latchkey runs your GitHub Actions on managed runners that detect this failure, apply the fix, and retry the job automatically - self-healing is on by default.