为什么 dotnet 5 docker 容器在运行时失败?

时间:2021-04-26 16:34:37

标签: c# docker .net-5

我有一个 dotnet5 控制台应用程序,它位于解决方案中,并且依赖于其他同级项目。我使用 Visual Studio 工具创建了 Docker 文件,这是 Docker 文件:

FROM mcr.microsoft.com/dotnet/runtime:5.0-buster-slim AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build
WORKDIR /src
COPY ["src/MyProject/MyProject.Launcher/MyProject.Launcher.csproj", "src/MyProject/MyProject.Launcher/"]
COPY ["src/MyProject/MyProject.DataAccess/MyProject.DataAcess.csproj", "src/MyProject/MyProject.DataAccess/"]
COPY ["src/MyProject/MyProject.Service/MyProject.Service.csproj", "src/MyProject/MyProject.Service/]
COPY ["src/Domain/MyProject.Domain.Model/MyProject.Domain.Model.csproj", "src/Domain/MyProject.Domain.Model/"]
RUN dotnet restore "src/MyProject/MyProject.Launcher/MyProject.Launcher.csproj"
COPY . .
WORKDIR "/src/src/MyProject/MyProject.Launcher"
RUN dotnet build "MyProject.Launcher.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "MyProject.Launcher.csproj" -c Release -o /app/publish

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

构建映像没问题,它正常添加到我的本地映像注册表,但是当我尝试运行此映像并创建容器时,出现此错误:

<块引用>

找不到任何兼容的框架版本 框架“Microsoft.AspNetCore.App”,版本“5.0.0”未找到。

  • 未找到任何框架。

您可以通过安装指定的框架来解决问题 和/或 SDK。

2 个答案:

答案 0 :(得分:2)

将此用作您的基本图像:

来自 mcr.microsoft.com/dotnet/aspnet:5.0.0-buster-slim AS base

答案 1 :(得分:1)

我认为您应该检查 docker hub 并搜索 .NET 5 SDK,然后在您的 容器 上安装该图像,然后它将被修复:

enter image description here

我找到了 Dotnet 3.1 SDK 但尝试找到 dotnet 5 SDK

我认为安装后这个错误会被修复

抱歉我的英语不好

:)