core icon indicating copy to clipboard operation
core copied to clipboard

COPY failed: stat /var/lib/docker/tmp/docker-builder492837088/myMicroservice.csproj: no such file or directory

Open kaisernayan opened this issue 7 years ago • 27 comments

Problem encountered on https://dotnet.microsoft.com/learn/web/aspnet-microservice-tutorial/docker-image Operating System: windows

Following the tutorial I am on step Create Docker image. I run the command "docker build -t mymicroservice ." from PowerShell. Then I got Copy Failed message that says "COPY failed: stat /var/lib/docker/tmp/docker-builder492837088/myMicroservice.csproj: no such file or directory"

Following is the detail response after the command -

Sending build context to Docker daemon 1.162MB Step 1/14 : FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base ---> 2f7531819f40 Step 2/14 : WORKDIR /app ---> Using cache ---> dfeed7f9bed8 Step 3/14 : FROM microsoft/dotnet:2.2-sdk AS build ---> 81d80198a492 Step 4/14 : WORKDIR /src ---> Using cache ---> fb38cbbb96c6 Step 5/14 : COPY myMicroservice.csproj myMicroservice/ COPY failed: stat /var/lib/docker/tmp/docker-builder492837088/myMicroservice.csproj: no such file or directory

My Docker file content is -

FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base WORKDIR /app

FROM microsoft/dotnet:2.2-sdk AS build WORKDIR /src COPY myMicroservice.csproj myMicroservice/ RUN dotnet restore myMicroservice/myMicroservice.csproj WORKDIR /src/myMicroservice COPY . . RUN dotnet build myMicroservice.csproj -c Release -o /app

FROM build AS publish RUN dotnet publish myMicroservice.csproj -c Release -o /app

FROM base AS final COPY --from=publish /app . ENTRYPOINT ["dotnet", "myMicroservice.dll"]

kaisernayan avatar Mar 14 '19 06:03 kaisernayan

has there been any update to this? I am having the exact same problem and cannot find the fix for it.

v8n3t avatar Mar 27 '19 14:03 v8n3t

Do you have a small repro we could try?

@leecow @dagood any idea where/how to route it?

karelz avatar Mar 30 '19 18:03 karelz

It looks like this is a generic error that happens when the file isn't found: https://stackoverflow.com/q/32997269.

Is it possible the Dockerfile is in a different directory from myMicroservice.csproj? From reading the instructions it looks like it might be easy to miss this step and accidentally create the Dockerfile in a different place:

Since you opened a new command prompt in the previous step, you'll need to return to the directory you created your service in.

/cc @MichaelSimons

dagood avatar Apr 01 '19 15:04 dagood

Any update on this? I am running into the same error.

I have the Dockerfile, myMicroService.csproj and the other files in the 'myMicroservice' folder.

shaun-rostami avatar Apr 04 '19 09:04 shaun-rostami

Any update on this? I am running into the same error.

I have the Dockerfile, myMicroService.csproj and the other files in the 'myMicroservice' folder.

This issue is waiting on more info from the opener. But from your comment, the extra capital in myMicroService.csproj might be the issue. I can't tell for sure without seeing your Dockerfile--it's possible you accounted for this. The tutorial and the Dockerfile in this issue description use myMicroservice.csproj.

Normally on Windows case doesn't matter, but Docker by default runs containers in a Linux VM where the file system is case-sensitive.

dagood avatar Apr 04 '19 14:04 dagood

I tried out the tutorial on my machine with Docker freshly installed to confirm what I'm thinking. The tutorial works when I follow the steps, but if I rename myMicroservice.csproj => myMicroService.csproj I hit the same error, so it does seem like the case is probably the problem:

## dagood E:\temp\repro-docker-microservice\myMicroservice
#> docker build -t mymicroservice .
[...]
 ---> 48031d26faf5
Step 5/14 : COPY myMicroservice.csproj myMicroservice/
COPY failed: stat /var/lib/docker/tmp/docker-builder270715569/myMicroservice.csproj: no such file or directory

## dagood E:\temp\repro-docker-microservice\myMicroservice
#> ls *.csproj
[...]
Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----         4/4/2019   2:22 PM            416 myMicroService.csproj

Hopefully this solves the issue for you @shaun-rostami, let me know if you're still having problems when the casing is the same. (A zip of your project wouldn't hurt!) Otherwise, I'm going to give @kaisernayan a few more days to get back to us then close the issue.

dagood avatar Apr 04 '19 19:04 dagood

Thanks @dagood! Yes the capital S in myMicroService.csproj was the problem.

shaun-rostami avatar Apr 04 '19 20:04 shaun-rostami

Awesome, thanks for confirming. 😄 (I could have been been clearer that what I was doing was simulating the error, and doing the opposite is what would fix your problem, sorry about that.)

dagood avatar Apr 04 '19 20:04 dagood

Seems addressed, closing.

karelz avatar Apr 05 '19 01:04 karelz

Hello, I solved the issue after working for two days. Previously,My file structure as follows ->nginx --->Dockerfile.dev --->default.conf

code of dockerfile.

 # escape=`
 FROM nginx
 COPY ./default.conf /etc/nginx/conf.d/default.conf
It was giving me the same error directory not found

My update File Structure ->nginx --->Dockerfile.dev --->nginx.conf

My updated code

 # escape=`
 FROM nginx
 COPY /nginx.conf /etc/nginx/conf.d/default.conf
Just notice i changed file name and removed ' . ' (dot) from starting.
now working fine

nischaypandey avatar Jan 19 '20 13:01 nischaypandey

What worked for me was ridiculous thing. I had to change absolute path COPY /app/config/services/nginx.conf /etc/nginx/nginx.conf to relative path COPY ./config/services/nginx.conf /etc/nginx/nginx.conf Still don't know why it failed with absolute path! but it worked ``

ldynia avatar Feb 17 '20 11:02 ldynia

@ldynia, When using the COPY instruction within a Dockerfile, the <src> path is relative to the build context. You would need to specify the root directory as your build context in order for an absolute path to work. This is not a recommended practice as it dramatically affects your docker build performance. You can read me about this in the Dockerfile reference documentation.

MichaelSimons avatar Feb 18 '20 14:02 MichaelSimons

I managed to resolve mine by running the command from the folder above (where I had my solution file). If you look in the folder above, you will see visual studio adds a .dockerignore file there. That gave me the clue that it must be running from that directory. the link at the top of the page helps explains how visual studio runs the docker file https://aka.ms/containerfastmode

princeo911 avatar Feb 28 '20 12:02 princeo911

@princeo911 yes, that worked, also we have to move Dockerfile to the root. So the problem boil downs to that if we generate doclerfile using Visual Studio (Right click on project -> Add -> Docker support) then we manually have to copy the file to the root.

Ideally, Visual Studio team should fix it.

RupenAnjaria avatar Apr 08 '20 15:04 RupenAnjaria

@princeo911 yes, that worked, also we have to move Dockerfile to the root. So the problem boil downs to that if we generate doclerfile using Visual Studio (Right click on project -> Add -> Docker support) then we manually have to copy the file to the root.

Ideally, Visual Studio team should fix it.

As an extension, I than ran into not being able to run the project in visual studio anymore, so I solved it with the following link: https://stackoverflow.com/questions/58469964/no-dockerfile-could-be-found-please-make-sure-you-have-a-dockerfile-called-doc

tl;dr I added the following to the project file.

DockerfileContext>.</DockerfileContext DockerfileFile>..\Dockerfile</DockerfileFile

vanhoutenbos avatar May 04 '20 09:05 vanhoutenbos

For me, this ended up being a casing issue for a reference to a project file in my Dockerfile.

10derloin avatar May 12 '20 14:05 10derloin

Do this: docker build -f Dockerfile .. to resolve the issue. Reference: https://docs.microsoft.com/en-us/visualstudio/containers/container-build?view=vs-2019#building-from-the-command-line

kwameg-a avatar May 24 '20 12:05 kwameg-a

@princeo911 yes, that worked, also we have to move Dockerfile to the root. So the problem boil downs to that if we generate doclerfile using Visual Studio (Right click on project -> Add -> Docker support) then we manually have to copy the file to the root.

Ideally, Visual Studio team should fix it.

thanks! it's worked

TymurMirzaiev avatar Jun 17 '20 18:06 TymurMirzaiev

Do this: docker build -f Dockerfile .. to resolve the issue. Reference: https://docs.microsoft.com/en-us/visualstudio/containers/container-build?view=vs-2019#building-from-the-command-line

This solution needs more attention. For me as a beginner it was exactly this problem, Visual Studio Created the file 1 directory deeper as it was supposed. Thank you.

T0miii avatar Jul 02 '20 17:07 T0miii

This happen Visual Studio add docker compose file one level up in Dockerfile dir. that mean The Dockerfile creating to support docker-compose. easy step to resolve use "docker-compose" up to build images else you need to specify path as in above posts. eg "docker build -f .//Dockerfile ."

Damdias avatar Jul 22 '20 03:07 Damdias