Recently, I've created an ASP.Net Core project on Visual Studio 2019 with Docker Support enabled. It's then created me a full Dockerfile so I don't have to worry about this.
If I launch my application from Visual Studio, using the Docker launch settings, it builds perfectly and then runs, which is perfect !
But when I try to build it by hand using the docker build command, I get an error telling me:
COPY failed: stat /var/lib/docker/tmp/docker-builder563776422/Back/Back.csproj: no such file or directory
with Back being the name of my solution and the name of my only project in this solution.
If I then change the following line:
COPY ["Back/Back.csproj", "Back/"]
to
COPY ["Back.csproj", "Back/"]
it now builds with the command. This modification seems logical to me since the Dockerfile is already located inside of my project's folder, and not at the root of the solution.
I'm a bit lost here, why did it work on Visual Studio before the modification? Am I right to change this line?
Here is the full Dockerfile (before modification):
FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-buster-slim AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/core/sdk:3.0-buster AS build
WORKDIR /src
COPY ["Back/Back.csproj", "Back/"]
RUN dotnet restore "Back/Back.csproj"
COPY . .
WORKDIR "/src/Back"
RUN dotnet build "Back.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Back.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Back.dll"]
