When building Docker images outside of Visual Studio, you may encounter this error:
failed to solve with frontend dockerfile.v0: failed to create LLB definition: failed to compute cache key: not found
Strangely, the same project might build perfectly inside Visual Studio. Why does this happen? Let’s break it down.
1️⃣ Why It Works in Visual Studio but Fails in CLI
Visual Studio integrates with Docker and manages the build context for you. That means it includes the correct files and paths when running docker build.
When you run docker build manually from the command line, you may be missing files or using the wrong build context. Docker can’t find those files, so it throws the “not found” cache key error.
2️⃣ Common Causes of the Error
- Wrong build context
- Example: You run the command from the wrong folder.
- Dockerfile might expect
COPY ./src /appbut your current directory doesn’t containsrc.
docker build -t myapp -f Dockerfile . - Files outside of Docker’s build context
- Docker can only access files inside the build context (the directory you specify in the
docker buildcommand). - If your Dockerfile tries to copy something outside this context, it will fail.
- Docker can only access files inside the build context (the directory you specify in the
.dockerignoreexcluding files- If
.dockerignoreexcludes files that are required in the build, Docker won’t find them.
.dockerignoreand ensure essential files aren’t being ignored.- If
- Multi-stage builds referencing missing files
- If you use multi-stage builds, a
COPY --from=builderstep may fail if the referenced file wasn’t generated in the earlier stage.
- If you use multi-stage builds, a
3️⃣ Example: Visual Studio Works, CLI Fails
Dockerfile:
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["MyApp/MyApp.csproj", "MyApp/"]
RUN dotnet restore "MyApp/MyApp.csproj"
COPY . .
WORKDIR "/src/MyApp"
RUN dotnet build "MyApp.csproj" -c Release -o /app/build
If you run:
docker build -t myapp .
from the wrong directory, Docker won’t find MyApp/MyApp.csproj.
✅ Fix: Run it from the solution root:
docker build -t myapp -f MyApp/Dockerfile .
4️⃣ How to Debug
- Run with verbose output:
DOCKER_BUILDKIT=0 docker build .This gives more detailed error messages. - Double-check your build context:
docker build -t myapp -f Dockerfile <context_directory> - Verify file paths inside the container’s build environment.
📌 Summary
The error
“failed to compute cache key: not found”
usually means Docker can’t find a file that the Dockerfile references.
- Visual Studio fixes this automatically by setting the correct build context.
- On the CLI, you need to carefully set your build context, check
.dockerignore, and validate paths.
👉 Next time you see this, double-check where you’re running docker build from—that’s usually the culprit.