Search code examples
c#dockerasp.net-coreconsole-application.net-6.0

Unable to run Docker .NET 6 console image


Hi I have below dockerfile for .NET 6 console app

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 ["MyProj/MyProj.csproj", "MyProj/"]
RUN dotnet restore "MyProj/MyProj.csproj"
COPY . .
WORKDIR "/src/MyProj"
RUN dotnet build "MyProj.csproj" -c Release -o /app/build

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

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

I am using github actions CI tool to build the image and deploying it in kubernets. I am not getting any error when building but when the image runs I get below error

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

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

No frameworks were found.

Learn about framework resolution:
https://aka.ms/dotnet/app-launch-failed

To install missing framework, download:
https://aka.ms/dotnet-core-applaunch?framework=Microsoft.AspNetCore.App&framework_version=6.0.0&arch=x64&rid=debian.11-x64

Below is csproj packagaes

<ItemGroup>
        <PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
        <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
        <PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="7.0.0" />
        <PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="7.0.0" />
        <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
        <PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="5.0.0" />
        <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
        <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.17.0" />
        <PackageReference Include="Npgsql" Version="7.0.2" />
        <PackageReference Include="OpenTelemetry" Version="1.3.0-rc.2" />
        <PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.1.0" />
        <PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.1.0" />
        <PackageReference Include="OpenTelemetry.Exporter.Prometheus" Version="1.3.0-rc.2" />
        <PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.0.0-rc9" />
        <PackageReference Include="prometheus-net" Version="7.0.0" />
        <PackageReference Include="prometheus-net.AspNetCore" Version="7.0.0" />
        <PackageReference Include="Npgsql" Version="7.0.2" />

I am not able to find the root cause of it. It was working fine few days back suddenly It started giving this error. Can someone help me to find the root cause. Any help would be appreciated.

I am expecting to run the image successfully.


Solution

  • Change the 1st line:
    FROM mcr.microsoft.com/dotnet/runtime:6.0 AS base
    to
    FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base