Skip to content
Latchkey

Docker "failed to compute checksum of ref" (file changed during build) in CI

BuildKit checksums files in the context to key its cache. If a file is rewritten, truncated, or deleted by another process while BuildKit is reading it, the hash cannot be computed and the solve fails. This is a race against a concurrent writer, not a Dockerfile defect.

What this error means

A docker build fails with failed to compute checksum of ref ...: failed to walk ...: file changed, usually when another step writes into the context during the build. Re-running on a stable tree succeeds. Latchkey managed runners auto-retry transient infrastructure failures, so a build that lost the race to a momentary concurrent write is typically retried cleanly on the next attempt.

docker
ERROR: failed to solve: failed to compute checksum of ref abc123::xyz: "/app/dist/bundle.js": file changed during build

Common causes

A concurrent process writing into the context

A watcher, codegen step, or test run rewriting files while the build hashes them changes the bytes mid-read.

Build output landing in the context

A prior step that writes into the same directory the build is reading creates a moving target.

A transient filesystem flake on the runner

An ephemeral I/O hiccup can make a stable file appear to change mid-walk.

How to fix it

Stop writing into the context during the build

  1. Finish all codegen/compilation steps before the build starts.
  2. Exclude generated output that does not belong in the image with .dockerignore.
.dockerignore
# .dockerignore
dist
.cache
coverage

Retry on a quiesced tree

  1. Ensure no background watcher is running, then re-run the build.
  2. If it passes on a stable tree, the original failure was a write race.
Terminal
docker build -t myorg/app:ci .

How to prevent it

  • Sequence build-context generation before docker build, never alongside it.
  • Ignore generated/output directories so the build never hashes a moving target.

Frequently asked questions

What causes ""file changed during build""?
A watcher, codegen step, or test run rewriting files while the build hashes them changes the bytes mid-read.
How do I fix "file changed during build"?
Stop writing into the context during the build

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card