在Ubuntu中运行.NET控制台Docker映像失败

4zcjmb1e  于 2023-01-31  发布在  .NET
关注(0)|答案(1)|浏览(335)

为一个.NET控制台应用程序创建一个Docker映像。但是当尝试运行该映像时,它抛出错误。
以下部分包含Dockerfile内容,

#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/runtime:6.0
COPY bin/Release/net6.0/publish .
ENTRYPOINT ["dotnet", "MySampleApplication.dll"]`

以下是我在尝试运行Docker映像时得到的错误,

docker run collector

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

App: /MySampleApplication.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`

尝试在Ubuntu中安装.NET sdk和运行时环境,但仍然存在相同的问题。

lf5gs5x2

lf5gs5x21#

你的应用程序可能从控制台运行,但在MS术语中,它不是控制台应用程序。你会收到一条消息,说Framework: 'Microsoft.AspNetCore.App', version '6.0.0' (x64),这告诉我们这是一个ASP.NET应用程序。ASP.NET不包括在console映像中,但它 * 包括在aspnet映像中。
因此,将Dockerfile更改为

#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/aspnet:6.0
COPY bin/Release/net6.0/publish .
ENTRYPOINT ["dotnet", "MySampleApplication.dll"]

当您运行它时,您需要将端口80Map到一个主机端口,以便能够与应用程序通信。

docker run -d -p 8080:80 collector

然后,您应该能够从主机访问http://localhost:8080/上的应用程序。

相关问题