Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker - failed to compute cache key: not found - runs fine in Visual Studio

I've generated a Dockerfile with Visual Studio. It runs in Visual Studio just fine and now I'm trying to build it from Windows itself (docker build ., and I tried many combinations). Yet I get the following error:

Error code

When I change copy to ./client.csproj it does continue and then I get:

Second error with changed copy path

What am I doing wrong? I changed Docker Linux to Windows, changed WSL, and restarted everything.

Dockerfile client

like image 698
Sjardi Djoy Willems Avatar asked Feb 10 '21 22:02

Sjardi Djoy Willems


People also ask

Where is .dockerignore file located?

dockerignore file is on the root directory of your context, it will ignore it if it is somewhere in the subfolder.

What does Workdir do in Dockerfile?

The WORKDIR command is used to define the working directory of a Docker container at any given time. The command is specified in the Dockerfile. Any RUN , CMD , ADD , COPY , or ENTRYPOINT command will be executed in the specified working directory.

What is Docker_buildkit?

BuildKit works on multiple export formats such as OCI or Docker along with the Support of Frontends (Dockerfile) and provides features such as efficient caching and running parallel build operations. BuildKit only needs container runtime for its execution and currently supported runtimes include containerd and runc.

What is Docker build context?

The docker build command builds Docker images from a Dockerfile and a “context”. A build's context is the set of files located in the specified PATH or URL . The build process can refer to any of the files in the context. For example, your build can use a COPY instruction to reference a file in the context.

How to fix Docker failed to compute cache key?

Check your .dockerignore file. Possible it ignores needed files for copy command and you get failed to compute cache key error. Share Follow answered Jun 10 '21 at 21:42

Can a dockerfile run in Visual Studio?

windows - Docker - failed to compute cache key: not found - runs fine in Visual Studio - Stack Overflow I've generated a Dockerfile with Visual Studio. It runs in Visual Studio just fine and now I'm trying to build it from Windows itself (docker build ., and I tried many combinations).

Is Docker build case sensitive in directory name?

3 In my case I found that docker build is case sensitive in directory name, so I was writing /bin/release/net5.0/publish in the COPY instruction and failed with the same error, I've just changed to /bin/Release/net5.0/publish and it worked Share Follow answered May 18 '21 at 13:22 Luis Diego RojasLuis Diego Rojas

What is the path to the dockerfile copyinstruction?

Any paths (such as with the COPYinstruction in the dockerfile) are relative to the location specified. The .means "current directory", which in my example is \WorkerService2.


2 Answers

Check your .dockerignore file. Possible it ignores needed files for copy command and you get failed to compute cache key error.

like image 106
Rimalon Avatar answered Oct 23 '22 03:10

Rimalon


The way Visual Studio does it is a little bit odd.

Instead of launching docker build in the folder with the Dockerfile, it launches in the parent folder and specifies the Dockerfile with the -f option.

I was using the demo project (trying to create a minimal solution for another question) and struck the same situation.

Setup for my demo project is

\WorkerService2  ("solution" folder)    +- WorkerService2.sln    +- WorkserService2  ("project" folder)        +- DockerFile        +- WorkerService2.csproj        +- ... other program files 

So I would expect to go

cd \Workerservice2\WorkerService2 docker build . 

But I get your error message.

 => ERROR [build 3/7] COPY [WorkerService2/WorkerService2.csproj, WorkerService2/]                                                                                                                        0.0s ------  > [build 3/7] COPY [WorkerService2/WorkerService2.csproj, WorkerService2/]: ------ failed to compute cache key: "/WorkerService2/WorkerService2.csproj" not found: not found 

Instead, go to the parent directory, with the .sln file and use the docker -f option to specify the Dockerfile to use in the subfolder:

cd \Workerservice2 docker build -f WorkerService2\Dockerfile --force-rm -t worker2/try7 .  docker run -it worker2/try7     

Edit (Thanks Mike Loux, tblev & Goku):

Note the final dot on the docker build command.

For docker the final part of the command is the location of the files that Docker will work with. Usually this is the folder with the Dockerfile in, but that's what's different about how VS does it. In this case the dockerfile is specified with the -f. Any paths (such as with the COPY instruction in the dockerfile) are relative to the location specified. The . means "current directory", which in my example is \WorkerService2.

I got to this stage by inspecting the output of the build process, with verbosity set to Detailed. If you choose Tools / Options / Projects and Solutions / Build and Run you can adjust the build output verbosity, I made mine Detailed.

like image 40
GregHNZ Avatar answered Oct 23 '22 05:10

GregHNZ