COPY failed: stat /var/lib/docker/tmp/docker-builder549405077/WebApplication1/WebApplication1.csproj: no such file or directory
Issue Title
COPY failed: stat /var/lib/docker/tmp/docker-builder549405077/WebApplication1/WebApplication1.csproj: no such file or directory
General
I have created one simple .net core web app and created docker file for the same.Below is the docker file content:
**FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base WORKDIR /app EXPOSE 80 EXPOSE 443
FROM microsoft/dotnet:2.2-sdk AS build WORKDIR /src COPY ["WebApplication1/WebApplication1.csproj", "WebApplication1/"] RUN dotnet restore "WebApplication1/WebApplication1.csproj" COPY . . WORKDIR "/src/WebApplication1" RUN dotnet build "WebApplication1.csproj" -c Release -o /app
FROM build AS publish RUN dotnet publish "WebApplication1.csproj" -c Release -o /app
FROM base AS final WORKDIR /app COPY --from=publish /app . ENTRYPOINT ["dotnet", "WebApplication1.dll"]**
I have run command: docker build -t webapp -f Dockerfile . for creating docker image.
CC @shirhatti @MichaelSimons
I faced the same issue and fixed it. Just replace COPY ["WebApplication1/WebApplication1.csproj", "WebApplication1/"] with COPY . WebApp1/ @sanjeev02saraswat
@sanjeev02saraswat, it looks like the reason COPY is failing is because the source path does not exist in your Docker build context. Your docker build command is passing in c:\users\sanjeev.x.sarasat\source\repos\WebApplication1\WebApplication1 as the build context directory which is the last parameter (e.g. .). To get this to work correctly you will either need to change your build context directory to c:\users\sanjeev.x.sarasat\source\repos\WebApplication1 or change the COPY source path to WebApplication1.csproj.
@sanjeev02saraswat, I suggest you to cd C:\Users\sanjeev.x.saraswat\source\repos\WebApplication1 and then type docker build -f WebApplication1/DockerFile -t webapp . (make sure docker file in this directory C:\Users\sanjeev.x.saraswat\source\repos\WebApplication1\WebApplication1)
@sanjeev02saraswat, I suggest you to cd C:\Users\sanjeev.x.saraswat\source\repos\WebApplication1 and then type docker build -f WebApplication1/DockerFile -t webapp . (make sure docker file in this directory C:\Users\sanjeev.x.saraswat\source\repos\WebApplication1\WebApplication1)
That worked for me, thank you so much! docker build -f AppName/DockerFile -t webapp .
I had to use the following command to start the build:
docker build .
Doing this: docker build -f Dockerfile .. should resolve the issue.
Reference: https://docs.microsoft.com/en-us/visualstudio/containers/container-build?view=vs-2019#building-from-the-command-line
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?
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?
tried @kwameg-a suggestion and that worked for me. docker build -t webapi -f Dockerfile ..
Closing, looks like this was answered.