Search code examples
docker.net-6.0serilog-aspnetcore

Unable to run .Net6 application as a Docker container with Serilog.AspNetCore


I have a .Net 6 Application running as a Docker Container. When I add the package of Serilog.AspNetCore v 6.1.0, the container fails to run with error as:

You must install or update .NET to run this application.

App: /app/PreAdviceGeneration.Presentation.dll
Architecture: x64
Framework: 'Microsoft.AspNetCore.App', version '6.0.0' (x64)
.NET location: /usr/share/dotnet/

No frameworks were found.

Following is my DockerFile:

FROM mcr.microsoft.com/dotnet/runtime:6.0 AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["ProjectA/ProjectA.csproj", "ProjectA/"]
COPY ["ProjectB/ProjectB.csproj", "ProjectB/"]
COPY ["ProjectC/ProjectC.csproj", "ProjectC/"]
RUN dotnet restore "ProjectA/ProjectA.csproj"
COPY . .
WORKDIR "/src/ProjectA"
RUN dotnet build "ProjectA.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "ProjectA.csproj" -c Release -o /app/publish /p:UseAppHost=false

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

It works just fine if I remove the package. I have installed .Net 6 with required architecture in my machine.


Solution

  • The serilog.aspnetcore package requires ASP.NET. The runtime image that you use as your base image doesn't have ASP.NET. You can use the aspnet image instead, like this

    FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base