Docker "failed to compute cache key: not found" in CI
BuildKit hashes the files a COPY/ADD references to compute its cache key. When a referenced path is absent from the build context, there is nothing to hash and the build fails before running the step.
What this error means
A docker build fails on a COPY/ADD line with failed to compute cache key: failed to calculate checksum of ref ...: "/path": not found. It is deterministic for a given context.
------
> [stage-1 3/7] COPY package.json package-lock.json ./:
------
ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref abc123: "/package-lock.json": not foundDiagnose it: build context, cache, or platform?
A Dockerfile that builds locally and fails in CI usually differs in one of three ways: the build context contains different files, the layer cache is cold or poisoned, or the runner architecture does not match what the base image provides.
# what is actually being sent as build context (dockerignore applies)
docker build --no-cache --progress=plain -t probe . 2>&1 | head -40
# what platform are you on, and what does the base image support?
docker version --format '{{.Server.Arch}}'
docker buildx imagetools inspect <base-image> | grep -i platform
# prove it is not a cache artefact
docker build --no-cache .Common causes
Source path not in the build context
The file or directory named in COPY does not exist relative to the build context root passed to docker build.
Path excluded by .dockerignore
A .dockerignore pattern removed the file from the context, so COPY cannot see it.
Wrong build context directory
The build was invoked with a context (the trailing path or CI working-directory) that does not contain the expected files.
How to fix it
Confirm the path and context
- List the build context to verify the file is present where COPY expects it.
- Check COPY paths are relative to the context root, not the Dockerfile location.
docker build -f Dockerfile -t app .
ls -la package-lock.jsonFix .dockerignore exclusions
- Ensure no .dockerignore pattern excludes a file you COPY.
- Re-include needed paths with a negation pattern if necessary.
# .dockerignore
node_modules
!package-lock.jsonKeep the build context small and deterministic
- A missing
.dockerignoresendsnode_modules,.git, and build output to the daemon, which is slow and can change layer hashes between environments. - A
COPYof a path that exists locally but is gitignored will fail in CI, because the runner only has what the checkout produced. - Multi-arch builds need
buildxand QEMU set up explicitly; a plaindocker buildon an ARM runner silently produces an ARM image.
How to prevent it
- Keep COPY paths relative to the build context root, audit .dockerignore against everything the Dockerfile copies, and set the correct context/working-directory in CI.