Docker Error Guide: 'failed to compute cache key: not found' — Fix Missing COPY/ADD Source Paths
Fix 'failed to compute cache key: path not found' in Docker: resolve COPY/ADD sources missing from the build context, .dockerignore exclusions, and wrong paths.
- #docker
- #troubleshooting
- #errors
- #buildkit
Stuck on this Docker with AI error? Get the free incident triage checklist
A one-page PDF — the exact steps to isolate, fix, and verify a production error like this one. No spam, unsubscribe anytime.
Overview
BuildKit fails while resolving a COPY or ADD instruction because the source path it needs to hash does not exist inside the build context:
failed to compute cache key: "/app/package.json" not found: not found
To cache a COPY, BuildKit fingerprints the source files. If the path is absent from the context, there is nothing to fingerprint, so the build stops before copying. The message names the exact path it could not find.
Symptoms
- The build runs until a
COPYorADDstep, then fails withfailed to compute cache key. - The named path looks correct in the Dockerfile but is missing from the sent context.
- The build works on one machine and fails on another (different working directory or checkout).
- The path exists on disk but is excluded by
.dockerignore.
Common Root Causes
- Wrong build context — running
docker buildfrom a directory that does not contain the source path, so it is never sent to the daemon. .dockerignoreexclusion — a pattern like*ornode_modulessilently drops the file from the context.- Path is relative to context, not the Dockerfile —
COPYsources are resolved against the build context root, not the Dockerfile’s location. - Typo or wrong case —
COPY Package.jsonwhen the file ispackage.json(case matters on the daemon’s filesystem). - File is generated later — copying a build artifact that has not been produced yet.
- Multi-stage
--fromtarget — copying from a stage or image where the path does not exist.
Diagnostic Workflow
Confirm which directory you are building from and what the Dockerfile expects:
pwd
grep -nE '^(COPY|ADD)' Dockerfile
Verify the file actually exists at the path relative to the context root:
ls -l ./app/package.json
Check whether .dockerignore is excluding it — BuildKit honours these patterns when assembling the context:
cat .dockerignore
Re-run the build with a plain progress log so you can see the failing step and its resolved source:
docker build --progress=plain -t myapp:1.4.2 .
If you pass an explicit context and Dockerfile, make sure the context (last argument) is the directory that holds the source files:
docker build -f docker/Dockerfile -t myapp:1.4.2 .
For COPY --from=builder, inspect that stage’s filesystem by targeting and running it:
docker build --target builder -t myapp-builder:1.4.2 .
docker run --rm myapp-builder:1.4.2 ls -l /app
Example Root Cause Analysis
A pipeline copied a compiled binary and failed:
failed to compute cache key: "/dist/server" not found: not found
The Dockerfile had:
COPY dist/server /usr/local/bin/server
cat .dockerignore revealed:
dist/
An earlier optimization added dist/ to .dockerignore to keep local builds small, which stripped the compiled binary out of the context sent to the daemon. Because BuildKit never received dist/server, it could not compute a cache key for the COPY. Removing that line from .dockerignore (the binary is built inside the image, or should be included) fixed the build. The general rule: if the path exists on disk but the build cannot find it, suspect .dockerignore first.
Prevention Best Practices
- Always run
docker buildfrom the repository root and pass.as the context, so relativeCOPYpaths resolve predictably. - Review
.dockerignorewhenever aCOPYfails — exclusions are the most common hidden cause. - Reference
COPYsources relative to the context root, never relative to the Dockerfile’s subdirectory. - Keep source paths lowercase and consistent to avoid case-sensitivity surprises between macOS and Linux daemons.
- Lint Dockerfiles with the Dockerfile validator so obvious path and instruction mistakes surface before a build agent runs them.
Quick Command Reference
pwd # confirm the build context directory
grep -nE '^(COPY|ADD)' Dockerfile # list source paths the build needs
ls -l ./path/to/source # verify the file exists in context
cat .dockerignore # check for exclusions
docker build --progress=plain -t myapp:1.4.2 .
docker build --target builder -t myapp-builder:1.4.2 .
Conclusion
failed to compute cache key: not found is BuildKit telling you a COPY/ADD source is missing from the context it received — not necessarily missing from disk. Check the build context directory, then .dockerignore, then the exact path and case. Building from the repo root with a clear .dockerignore prevents almost every occurrence. Find more build fixes in the Docker stack guides.
Fixed it? Get 500 Docker with AI & DevOps AI prompts — free
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.
Stuck on this? Start guided troubleshooting
Open an interactive diagnostic session with this error already loaded. Work a step-by-step plan, record what each check returns, land on a root cause, and export a clean incident summary — no account needed to start.
Did this fix your issue?
Solved it a different way?
Share the fix that worked for you — reviewed, then published to help the next engineer.
That looks like it may contain a secret (key, token, password, or connection string). Please remove it — a note with a detected secret can’t be published.
Thanks — that helps. Published notes appear after a quick review.
Trending errors this week
The error guides other engineers are actually reading right now.
- 1mount: wrong fs type, bad option, bad superblock
- 2Docker 'failed to set up container networking': Fix the Bridge and IP Pool
- 3Docker 'failed to create shim task': How to Fix the containerd Runtime Error
- 4Transport endpoint is not connected
- 5modprobe: FATAL: Module not found
- 6mount: wrong fs type, bad option, bad superblock
Get 500 Battle-Tested DevOps AI Prompts — Free
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.