Unable to build docker image from docker file, for dotnet core web application
The issue is in folder structure. You copied your source to /src
folder (see line 8 and 11 of Dockerfile), but *.csproj file is copied to amazing-app
subfolder.
You can check it by running "intermediate" image, eg: 781b4c552434
(it is a hash of image before crash), like following: docker run -it --rm --name xxx b5a968c1103c bash
and then you can inspect file system by ls
command to see that source code and csproj file are located in different places.
So, i suggest to move Dockerfile to root directory (close to .dockerignore) and update path to csproj file (also, you need to run docker build
command from root directory. This Dockerfile should work:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS baseWORKDIR /appEXPOSE 8989FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS buildWORKDIR /srcCOPY ["amazing-app/amazing-app.csproj", "amazing-app/"]RUN dotnet restore "amazing-app/amazing-app.csproj"COPY . .WORKDIR "/src/amazing-app"RUN dotnet build "amazing-app.csproj" -c Release -o /app/buildFROM build AS publishRUN dotnet publish "amazing-app.csproj" -c Release -o /app/publishFROM base AS finalWORKDIR /appCOPY --from=publish /app/publish .ENTRYPOINT ["dotnet", "amazing-app.dll"]