Skip to content
Latchkey

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.

docker
------
 > [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 found

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

  1. List the build context to verify the file is present where COPY expects it.
  2. Check COPY paths are relative to the context root, not the Dockerfile location.
Terminal
docker build -f Dockerfile -t app .
ls -la package-lock.json

Fix .dockerignore exclusions

  1. Ensure no .dockerignore pattern excludes a file you COPY.
  2. Re-include needed paths with a negation pattern if necessary.
.dockerignore
# .dockerignore
node_modules
!package-lock.json

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.

Related guides

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