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 foundCommon 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.jsonHow 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.