Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
kaisernayan opened this issue Mar 14, 2019 · 27 comments
Labels
area-tutorials Issues related to getting started tutorials

Comments

@kaisernayan
Copy link

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"]

@karelz karelz added the area-tutorials Issues related to getting started tutorials label Mar 19, 2019
@v8n3t
Copy link

v8n3t commented Mar 27, 2019

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

@karelz
Copy link
Member

karelz commented Mar 30, 2019

Do you have a small repro we could try?

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

@dagood
Copy link
Member

dagood commented Apr 1, 2019

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

@shaun-rostami
Copy link

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.

@dagood
Copy link
Member

dagood commented Apr 4, 2019

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
Copy link
Member

dagood commented Apr 4, 2019

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.

@shaun-rostami
Copy link

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

@dagood
Copy link
Member

dagood commented Apr 4, 2019

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.)

@karelz
Copy link
Member

karelz commented Apr 5, 2019

Seems addressed, closing.

@karelz karelz closed this as completed Apr 5, 2019
@nischaypandey
Copy link

nischaypandey commented Jan 19, 2020

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

@ldynia
Copy link

ldynia commented Feb 17, 2020

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
``

@MichaelSimons
Copy link
Member

@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.

@princeo911
Copy link

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

@RupenAnjaria
Copy link

@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.

@vanhoutenbos
Copy link

vanhoutenbos commented May 4, 2020

@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

@10derloin
Copy link

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

@kwameg-a
Copy link

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

@TymurMirzaiev
Copy link

@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

@T0miii
Copy link

T0miii commented Jul 2, 2020

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.

@Damdias
Copy link

Damdias commented Jul 22, 2020

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 ."

@vinaysaroha
Copy link

It will work if you use COPY ./myMicroservice.csproj myMicroservice/

100% it will work try it .

@ZedZipDev
Copy link

I have VS 2019 Solution with 2 projects: P1 (Standard lib) & P2 (ASP.NET Core exe).
P2 contains a Dockerfile.
I have copied the Docker file to up folder, tried to build the docker running the cmd :

>docker build -f Dockerfile ..
Sending build context to Docker daemon  3.056GB
Step 1/18 : FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
 ---> 5d7a95ed1660
Step 2/18 : WORKDIR /app
 ---> Using cache
 ---> 6e8271ae3df9
Step 3/18 : EXPOSE 80
 ---> Using cache
 ---> e45066aa184b
Step 4/18 : EXPOSE 443
 ---> Using cache
 ---> 0bbce5ed4c30
Step 5/18 : FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
 ---> 925a86b607a3
Step 6/18 : WORKDIR /src
 ---> Using cache
 ---> e4af901c8e34
Step 7/18 : COPY ["PropMan/PropMan.csproj", "PropMan/"]
COPY failed: stat /var/lib/docker/tmp/docker-builder808977273/PropMan/PropMan.csproj: no such file or directory
PS D:\MyProjects\PM2020\PMan>

How to fix it?

@Sourcephy
Copy link

vs2019 asp.net core 3.1 docker(linux) - working test

#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["webapp.csproj", "./"]
RUN dotnet restore "./webapp.csproj"
COPY . .
#WORKDIR "/src/webapp"
RUN dotnet build "webapp.csproj" -c Release -o /app/build

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

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


docker run -d -p 8000:80 --name runapp webapp

@camerontbelt
Copy link

camerontbelt commented Sep 15, 2020

Im adding my comment for posterity. The issue I had was that visual studio had put the .csproj file too deep in the path inside the Dockerfile
Notice the difference between line 10 in each section. When I tried to build the docker file it was trying to copy the csproj file from one level below it an the folder called MyApp. But that folder didnt exist as I was already inside of MyApp trying to run the dockerfile.
Ex.

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster 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

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

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

Changed to

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["MyApp.csproj", "MyApp/"]
RUN dotnet restore "MyApp/MyApp.csproj"
COPY . .
WORKDIR "/src/MyApp"
RUN dotnet build "MyApp.csproj" -c Release -o /app/build

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

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

@Lechus
Copy link

Lechus commented Nov 16, 2020

Will it be fixed at all?

@vaibhavrmore1
Copy link

Generated the docker file of my existing azure function project from the left menu Docker Support.

During the build in devops, it's throwing error as :
##[error]COPY failed: stat /var/lib/docker/tmp/docker-builder173318253/SICDP.Functions.KlaviyoImport/SICDP.Functions.KlaviyoImport.csproj: no such file or directory

The docker file auto-generated is :
`#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/azure-functions/dotnet:3.0 AS base
WORKDIR /home/site/wwwroot
EXPOSE 80

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["SICDP.Functions.KlaviyoImport/SICDP.Functions.KlaviyoImport.csproj", "SICDP.Functions.KlaviyoImport/"]
COPY ["SICDP.Services/SICDP.Services.Models/SICDP.Services.Models.csproj", "SICDP.Services/SICDP.Services.Models/"]
RUN dotnet restore "SICDP.Functions.KlaviyoImport/SICDP.Functions.KlaviyoImport.csproj"
COPY . .
WORKDIR "/src/SICDP.Functions.KlaviyoImport"
RUN dotnet build "SICDP.Functions.KlaviyoImport.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "SICDP.Functions.KlaviyoImport.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /home/site/wwwroot
COPY --from=publish /app/publish .
ENV AzureWebJobsScriptRoot=/home/site/wwwroot
AzureFunctionsJobHost__Logging__Console__IsEnabled=true`

Is any issue in it?

@lindexi
Copy link

lindexi commented Dec 9, 2021

Q: How to solve docker command work folder are not right ?

A: Using the DockerfileContext to set the WorkingDirectory

  <PropertyGroup>
    <DockerfileContext>..\..\..</DockerfileContext>
  </PropertyGroup>

See microsoft/DockerTools#161 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-tutorials Issues related to getting started tutorials
Projects
None yet
Development

No branches or pull requests