ERROR: failed to solve: failed to compute cache key: not found
Resolve Docker buildkit "failed to compute cache key: not found" errors caused by .dockerignore exclusions or incorrect COPY source paths.
Root Cause Mechanical Summary
BuildKit cannot find the file or directory specified in a COPY or ADD instruction relative to the build context. This occurs when relative paths are incorrect or the file is inadvertently ignored in .dockerignore.
Docker resolves `COPY <src> <dest>` against the directory path passed to `docker build <context>`. If .dockerignore matches `<src>`, or `<src>` points to a directory outside the build context, BuildKit fails during cache resolution.
# Fails if run from subfolder or file ignored
COPY ../shared/package.json ./# Correct: build context set to repository root
# Run: docker build -f apps/web/Dockerfile .
COPY shared/package.json ./shared/
COPY apps/web/package.json ./apps/web/Resolution Note: Docker cannot access parent directories `../` outside the build context root. Execute docker build from root.
Step-by-Step Triage Checklist
Check `.dockerignore` to confirm your source file is not excluded (e.g. `dist/` or `package-lock.json`).
Verify the build command context: run `docker build -t app .` from the folder containing the file.
Check case sensitivity: Linux containers enforce case-sensitive filenames (e.g., `app.ts` vs `App.ts`).
Pre-Build Context Verification Script
Prevent recurrence by enforcing this verification check in staging or pre-commit hooks:
#!/usr/bin/env bash
if [ ! -f "package.json" ]; then
echo "Error: package.json must exist in Docker build context"
exit 1
fi
docker build --check .
Quick CLI Fix / Diagnosis
docker build --no-cache -f Dockerfile .DevFlow Diagnostic Workbench Tools
Frequently Asked Questions
- Can Docker COPY access files outside the build context?
- No. For security reasons, Docker build contexts cannot reference files outside the specified root directory.