skip to Main Content

I created a Console application using .NET 8.0 to build my background services. When I deploy this in an AKS cluster I get this error.

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

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

No frameworks were found.

The code below shows the builder in Program.cs and the Dockerfile. The AKS cluster that I am using has several .NET 8.0 ASP.NET Core projects deployed so I’m a bit confused why I’m being asked to install .NET. The only difference with this application is that it’s a console application instead of a Web API application.

// Program.cs
static void Main(string[] args)
{
    IServiceCollection serviceDescriptors = new ServiceCollection();
    Host.CreateDefaultBuilder(args)
        .ConfigureHostConfiguration(configure =>
        {
            configure.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                .AddJsonFile("appsettings.Development.json", optional: true, reloadOnChange: true)
                .Build();
        })
        .ConfigureServices((hostContext, services) =>
        {
            var appSettingsConfig = hostContext.Configuration.GetSection(nameof(AppSettings));

            services.Configure<AppSettings>(appSettingsConfig);

            services.AddHostedService<SampleBackgroundService>();
        })
        .Build()
        .Run();
}

And

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

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["src/SampleBackgroundService/SampleBackgroundService.csproj", "src/SampleBackgroundService/"]
RUN dotnet restore "./src/SampleBackgroundService/SampleBackgroundService.csproj"
COPY . .
WORKDIR "/src/src/SampleBackgroundService"
RUN dotnet build "./SampleBackgroundService.csproj" -c $BUILD_CONFIGURATION -o /app/build

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

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

If anyone can guide me on how to fix this, it would be appreciated!

2

Answers


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

    As provided by Microsoft asp.net core doc

    Login or Signup to reply.
  2. The error indicates that the application requires the ASP.NET Core runtime, but the container image you are using in the dockerfile is the base image. mcr.microsoft.com/dotnet/runtime:8.0 only includes the base.NET runtime, not theASP.NET Core runtime

    The runtime image mcr.microsoft.com/dotnet/runtime:8.0 is designed for plain.NET applications that do not depend on the ASP.NET Core framework

    To resolve the issue, you may change the image from the base image to use the ASP.NET Core runtime image. mcr.microsoft.com/dotnet/aspnet:8.0Follow the ASP.NET Core Runtime Image for more details.

    Here is the updated Dockerfile with ASP.NET Core Runtime Image.

    FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
    WORKDIR /app
    
    FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
    ARG BUILD_CONFIGURATION=Release
    WORKDIR /src
    COPY ["src/SampleBackgroundService/SampleBackgroundService.csproj", "src/SampleBackgroundService/"]
    RUN dotnet restore "./src/SampleBackgroundService/SampleBackgroundService.csproj"
    COPY . . 
    WORKDIR "/src/src/SampleBackgroundService"
    RUN dotnet build "./SampleBackgroundService.csproj" -c $BUILD_CONFIGURATION -o /app/build
    
    FROM build AS publish
    ARG BUILD_CONFIGURATION=Release
    RUN dotnet publish "./SampleBackgroundService.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
    
    FROM base AS final
    WORKDIR /app
    COPY --from=publish /app/publish .
    USER $APP_UID
    ENTRYPOINT ["dotnet", "SampleBackgroundService.dll"]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search