Unable to run Docker .NET 6 console image
Asked Answered
S

3

10

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.

Samarium answered 30/3, 2023 at 11:55 Comment(1)
You want the asp.net core runtime docker image: hub.docker.com/_/microsoft-dotnet-aspnetHovercraft
B
24

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

Brass answered 30/3, 2023 at 13:1 Comment(1)
worked thanks a lot. spent almost week to figure it outSamarium
S
3

It seems that one of the packages relies on ASP.NET Core runtime being present (prometheus-net.AspNetCore would be primary candidate based on the <FrameworkReference Include="Microsoft.AspNetCore.App" /> in the csproj).

Either change base to FROM mcr.microsoft.com/dotnet/aspnet:6.0, or find the "guilty" package and remove it.

Possibly relevant - The framework 'Microsoft.AspNetCore.App', version '6.0.0' (x64) was not found

Spleeny answered 30/3, 2023 at 12:48 Comment(0)
T
0

I solved this issues with:

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
...
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build

While i was playing with different configurations i faced with fact - build existed with code 1 without any details. First time i thought it was because of incorrect choise sdk...aspnet etc. But after investigation, i found: C:\Users\<UserName>\AppData\Local\Temp\tmp7082.tmp with details. And the problem was in fact 1 projectA refers another projectB, but both of the have appsettings.json, and build process failed because of this collision (2 files with the same name in 1 path)

Traitorous answered 23/4, 2024 at 22:21 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.