为什么此停靠文件丢失了对.NET运行时的引用?

vmdwslir  于 2022-11-19  发布在  .NET
关注(0)|答案(1)|浏览(123)

我有一个这样的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 ["Project/Project.csproj", "Project/"]
COPY ["Reference/Reference.csproj", "Reference/"]
RUN dotnet restore "Project/Project.csproj"
RUN dotnet restore "Reference/Reference.csproj"
COPY . .
WORKDIR "/src/Project"
RUN dotnet build "Project.csproj" -c Release -o /app/build

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

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

但是当我想用docker build -f Dockerfile -t mytag . && docker run --name myproject mytag构建并运行它时,我在构建后得到一个错误:

You must install or update .NET to run this application.
2022-11-09T15:48:22.642099385Z 
2022-11-09T15:48:22.642104961Z App: /app/Project.dll
2022-11-09T15:48:22.642108153Z Architecture: x64
2022-11-09T15:48:22.642111392Z Framework: 'Microsoft.AspNetCore.App', version '6.0.0' (x64)
2022-11-09T15:48:22.642115860Z .NET location: /usr/share/dotnet/
2022-11-09T15:48:22.642119020Z 
2022-11-09T15:48:22.642122144Z No frameworks were found.

为什么会这样?

tzcvj98z

tzcvj98z1#

runtime映像适用于控制台应用程序。您的应用程序是ASP.NET应用程序,因此应改用aspnet运行时映像。替换

FROM mcr.microsoft.com/dotnet/runtime:6.0 AS base

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base

相关问题