无法运行 Docker .NET 6 控制台映像

Unable to run Docker .NET 6 console image

提问人:Niranjan 提问时间:3/30/2023 最后编辑:Guru StronNiranjan 更新时间:3/31/2023 访问量:1713

问:

嗨,我有以下适用于 .NET 6 控制台应用程序的 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 ["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"]

我正在使用 github actions CI 工具构建映像并将其部署在 Kubernetes 中。我在构建时没有收到任何错误,但是当映像运行时,我收到以下错误

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

下面是 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" />

我无法找到它的根本原因。几天前它工作正常,突然它开始出现这个错误。有人可以帮我找到根本原因吗?任何帮助将不胜感激。

我期望成功运行映像。

C# docker asp.net-core 控制台应用程序 net-6.0

评论

0赞 Blue 3/30/2023
需要 asp.net 核心运行时 docker 映像:hub.docker.com/_/microsoft-dotnet-aspnet

答:

1赞 Guru Stron 3/30/2023 #1

似乎其中一个软件包依赖于存在 ASP.NET 核心运行时(根据 csproj 中的 <FrameworkReference Include=“Microsoft.AspNetCore.App” /> 将是主要候选者)。prometheus-net.AspNetCore

要么更改为 ,要么找到“有罪”包并将其删除。baseFROM mcr.microsoft.com/dotnet/aspnet:6.0

可能相关 - 找不到框架“Microsoft.AspNetCore.App”版本“6.0.0”(x64)

10赞 Qiang Fu 3/30/2023 #2

将第一行:

更改为
FROM mcr.microsoft.com/dotnet/runtime:6.0 AS base
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base

评论

1赞 Niranjan 3/31/2023
工作非常感谢。花了将近一周的时间才弄清楚