Skip to content
Latchkey

docker build: "write error: no space left on device"

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

  1. Add a .dockerignore to keep node_modules, .git, and artifacts out of the build context.
  2. Use multi-stage builds so only the final stage ships.
  3. 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.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →