Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

docker build stops at COPY with 'failed to compute cache key'

Errorfailed to compute cache key: "/app.csproj" not found: not found

Short answer

COPY and ADD only see files inside the build context, the directory you pass to docker build. The error means the source path is not in that context, or .dockerignore removed it. Run the build from the right folder, pass the right context with -f, or un-ignore the file.

  • Applies to Docker 27, BuildKit
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    List what the build context contains from the directory you build in.

    ls -la && docker build -f Dockerfile .
  2. 2Match what you see, then jump to its fix

    1. 1The failing path is a project file that exists on disk, often in a solution with several projects.The source path is outside or wrongly relative to the contextFix
    2. 2The file is in the context directory but still reported not found..dockerignore excludes the fileFix

What does the error look like?

  • failed to compute cache key: "/app.csproj" not found: not found
  • failed to solve: failed to compute cache key

Cause 1 of 2

The source path is outside or wrongly relative to the context

1Check

Paths resolve against the context root, and the Dockerfile location is set separately with -f. Files outside the context are unavailable.

docker build -f src/Api/Dockerfile .

2Fix

Use the solution root as the context and the Dockerfile via -f; write COPY paths relative to the context.

docker build -f src/Api/Dockerfile -t api .
# in the Dockerfile
COPY src/Api/Api.csproj src/Api/

3Verify

The COPY step now passes.

docker build -f src/Api/Dockerfile -t api .

Confirmed by docs.docker.com

Did this fix it?

Cause 2 of 2

.dockerignore excludes the file

1Check

Files that match .dockerignore are removed from the context before it is sent, so COPY cannot see them.

cat .dockerignore

2Fix

Add a negation after the pattern that hides the file (the last matching line wins).

*
!src/
!*.sln

3Verify

Build again.

docker build -t app .

Confirmed by docs.docker.com

Did this fix it?

How do I stop it coming back?

  • Write the exact docker build command in the README or Makefile, with the context.
  • Keep one .dockerignore per context and review it when files are added.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.