ERROR: failed to build: failed to solve: failed to compute cache key: failed to calculate
checksum of ref ...: "/appsettings.Production.json": not found — a COPY line
names a file that is not in the build context, the folder you passed to docker build
(the dot at the end). The file is missing, .dockerignore leaves it out, or you built
from the wrong folder. The quoted path is relative to that context.
Check in that order: does the quoted path exist under the folder you build from? If it does, read
the build output for a CopyIgnoredFile warning and fix .dockerignore. If
the Dockerfile sits in a project subfolder, build from the folder its paths start from, with
-f.
The error
#8 [4/4] COPY appsettings.Production.json /app/
#8 ERROR: failed to calculate checksum of ref p79fbnvyhjibpf8o7uvy1bb2s::t60kff9caua0nhlm1hqsvwm5m: "/appsettings.Production.json": not found
------
> [4/4] COPY appsettings.Production.json /app/:
------
Dockerfile:4
--------------------
2 | WORKDIR /app
3 | COPY appsettings.json /app/
4 | >>> COPY appsettings.Production.json /app/
5 | CMD ["ls", "-l", "/app"]
6 |
--------------------
ERROR: failed to build: failed to solve: failed to compute cache key: failed to calculate checksum of ref p79fbnvyhjibpf8o7uvy1bb2s::t60kff9caua0nhlm1hqsvwm5m: "/appsettings.Production.json": not found
Exit code 1. The two ids after ref change on every run.
Why it happens
docker build sends the context folder to BuildKit, minus whatever
.dockerignore excludes, and a COPY can read only from that snapshot, never
from the disk around it. BuildKit checksums the files each COPY needs to decide whether
its cache is still valid, and a file that is not in the snapshot fails at that step, hence the
cache-key wording for what is simply a missing file. The leading slash is the root of the context.
Three different mistakes gave this error in the test:
- The file is not there. The context held only
appsettings.json, as a fresh checkout does when the production file is kept out of Git. .dockerignoreexcludes it. The file existed, but the lineappsettings.*.jsonremoved it from the context. Docker 29.9 printed a warning above the same error:
- CopyIgnoredFile: Attempting to Copy file "appsettings.Production.json" that is excluded by .dockerignore (line 4)
- The wrong folder. A Dockerfile in
src/Apithat copiessrc/Api/appsettings.jsonexpects the solution folder as its context. Built from insidesrc/Api, it failed with"/src/Api/appsettings.json": not found, because the context had nosrcfolder.
The (line 4) in the warning is the Dockerfile's COPY line, not a line of .dockerignore.
The fix
For a missing file, put it into the context (or have the CI job create it) and build again. For
.dockerignore, add an exception after the pattern:
bin/
obj/
appsettings.*.json
!appsettings.Production.json
For the wrong folder, build from the solution folder and point -f at the Dockerfile:
PS> docker build -q -f src/Api/Dockerfile -t fix6-copy:c .
sha256:72845cfc74604db907ceeb69304f58737374f7b61a33b9c97de274dea8ed62b6
PS> docker run --rm --name fix6-copy-c fix6-copy:c
total 8
-rwxr-xr-x 1 root root 57 Oct 23 04:42 appsettings.Production.json
-rwxr-xr-x 1 root root 146 Oct 23 04:42 appsettings.json
All three builds then succeeded and the container listed both files. The dot is the context and
-f only says where the Dockerfile is, so the COPY paths are read from the
solution folder while the Dockerfile stays in the project.
How it was reproduced
Docker Desktop 4.96.3 with engine 29.9.2, building through BuildKit's default builder
(desktop-linux, docker driver) from Windows PowerShell 5.1, on the cached
alpine:latest image. A five-line Dockerfile with two COPY lines was built
in three folders, one per cause, and each fix was confirmed with a build and a
docker run that listed /app. The tags starting with
fix6-copy are the test's own and were removed afterwards.
Frequently asked
- What does 'failed to compute cache key' not found mean in docker build?
- A COPY or ADD line names a file that is not in the build context. BuildKit tries to checksum the file for its cache and cannot find it. The quoted path is relative to the context folder.
- Why does docker build not find a file that exists?
- Either .dockerignore excludes it, or the build context is a different folder from the one the COPY paths assume. Docker 29.9 printed a CopyIgnoredFile warning for the first case; for the second, build from the right folder and point -f at the Dockerfile.
- How do I build a Dockerfile that is in a subfolder?
- Run docker build from the folder the COPY paths start from and pass the Dockerfile with -f, for example docker build -f src/Api/Dockerfile . from the solution folder. The final dot is the build context.
More decoded errors in the Fixes category. The build context,
.dockerignore and a real two-stage .NET Dockerfile are covered in
Building the .NET Image, Part 7 of Docker
for .NET Developers on Windows.