.net core 5 docker 下面的例子不是 运行

.net core 5 docker following example not running

我按照我在网上找到的说明进行操作,这是我的 dockerfile:

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /source

# copy csproj and restore as distinct layers
COPY *.csproj .
RUN dotnet restore

# copy and publish app and libraries
COPY . .
RUN dotnet publish -c release -o /app --no-restore

# final stage/image
FROM mcr.microsoft.com/dotnet/runtime:5.0
WORKDIR /app
COPY --from=build /app .
ENTRYPOINT ["my-app"]

我也有一个 .dockerignore,因为我遇到了 dir length exceeded 错误:

Dockerfile
[b|B]in
[O|o]bj

当我尝试 运行 时,我收到此错误,指出未找到 aspnetcore:

It was not possible to find any compatible framework version
The framework 'Microsoft.AspNetCore.App', version '5.0.0' was not found.
  - No frameworks were found.

You can resolve the problem by installing the specified framework and/or SDK.

The specified framework can be found at:
  - https://aka.ms/dotnet-core-applaunch?framework=Microsoft.AspNetCore.App&framework_version=5.0.0&arch=x64&rid=debian.10-x64

我是不是做错了什么?

通常入口点看起来像 ENTRYPOINT ["dotnet", "my-app.dll"],而不仅仅是 ENTRYPOINT ["my-app"]

除了@mtkachenko 提到的入口点不正确的答案外,您有 aspnet 应用程序,因此您需要 aspnet 图书馆员。使用 mcr.microsoft.com/dotnet/aspnet:5.0.

而不是运行时图像 mcr.microsoft.com/dotnet/runtime:5.0