Docker "failed to compute cache key" - Fix BuildKit Cache Errors in CI
BuildKit hashes the inputs of a step to look up its cache. "failed to compute cache key" means it could not even produce that hash - usually because a referenced file is not in the context.
What this error means
The build fails with failed to compute cache key: failed to calculate checksum ... not found, naming a path. It is deterministic and points at a specific COPY/ADD source.
ERROR: failed to solve: failed to compute cache key: failed to calculate checksum
of ref ...: "/app/package-lock.json": not foundCommon causes
COPY source not in the build context
The path is wrong relative to the context root, or the file is excluded by .dockerignore, so BuildKit cannot checksum it to form a cache key.
Wrong build context directory
Running the build from the wrong directory (or with the wrong context: in compose/buildx) means the expected files are simply not present.
Stale or unreachable external cache
A --cache-from registry reference that no longer exists, or a corrupted cache, can fail the cache-key computation for cache-import steps.
How to fix it
Fix the COPY path and .dockerignore
Make the source path relative to the actual context and ensure it is not ignored.
# context is '.', so the file must exist at ./package-lock.json
docker build -t api .
grep -n package-lock .dockerignore # must NOT be excludedBust or disable a bad external cache
Rebuild without the failing cache import to confirm the cache is the issue.
docker build --no-cache .
# or drop a stale --cache-from reference and re-export fresh cacheHow to prevent it
- Keep COPY paths and the build context directory consistent across local and CI.
- Maintain an accurate .dockerignore so context contents are predictable.
- Validate
--cache-fromreferences exist before relying on them.