【问题标题】:Unable to run self contained .net core 5.0 application无法运行自包含的 .net core 5.0 应用程序
【发布时间】:2022-01-24 01:32:33
【问题描述】:

我有一个 .NET core 5.0 ASPNET Web API 应用程序。此应用程序在 Visual Studio 本地完美运行。

现在我正在尝试使用以下命令发布自包含应用程序:

dotnet publish -c release testdb.sln --framework net5.0 --runtime linux-x64 /p:DebugType=None /p:DebugSymbols=false --nologo --self-contained true -v m

我正在尝试在 Red Hat Linux 映像上运行它(图片详情如下):

NAME="Red Hat Enterprise Linux Server"
VERSION="7.6 (Maipo)"
ID="rhel"
ID_LIKE="fedora"
VARIANT="Server"
VARIANT_ID="server"
VERSION_ID="7.6"
PRETTY_NAME="Red Hat Enterprise Linux Server 7.6 (Maipo)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:redhat:enterprise_linux:7.6:GA:server"
HOME_URL="https://www.redhat.com/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"

REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 7"
REDHAT_BUGZILLA_PRODUCT_VERSION=7.6
REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"
REDHAT_SUPPORT_PRODUCT_VERSION="7.6"
Red Hat Enterprise Linux Server release 7.6 (Maipo)
Red Hat Enterprise Linux Server release 7.6 (Maipo)

这就是我的 docker 文件的样子:

FROM testrepo.net/images/base/rhel:7.6

#published code is copied inside redhat folder
COPY redhat/  APP/
WORKDIR APP
RUN chmod +x /APP
RUN chmod +x testdb.dll
RUN chmod 777 /APP

ENTRYPOINT "./testdb.dll"

当我运行这个图像时,我得到错误:./testdb.dll: cannot execute binary file

我不确定这是否是由于我在发布命令期间指定的无效runtime 或其他原因造成的。

【问题讨论】:

  • 错误是正确的——你不能只运行一个dll。你需要做的是运行dotnet testdb.dll。这意味着您的基础 docker 镜像需要安装 dotnet cli(或者您需要将其作为 dockerfile 的一部分进行安装——尽管大多数人使用 MS 提供的镜像:hub.docker.com/_/microsoft-dotnet-runtime
  • @RB。我如何解决它?这是一个没有 aspnet 运行时的 Linux 映像。所以我不能说 ~ENTRYPOINT ["dotnet","testdb.dll"]~ 我该如何解决这个问题?
  • 抱歉 - 我在移动设备上不小心点击了保存。我现在已经在我原来的评论中回答了你的问题 :) 当然使用 ASP.Net 基础图像作为 asp.net 应用程序 - MS 为所有场合提供图像 :)
  • @RB。由于这是一个自包含的图像,我不应该在没有 dotnet cli 或 dotnet runtime 的情况下运行该应用程序吗?
  • 哦,对不起 - 我错过了那个细节。它还应该创建一个名为testdb(无扩展名)的文件——这是可执行文件——你运行它。抱歉没有正确阅读问题!

标签: c# .net docker asp.net-core dotnet-publish


【解决方案1】:

将 RUN chmod +x testdb.dll 更改为 RUN chmod +x testdb 并将ENTRYPOINT "./testdb.dll" 更改为 ENTRYPOINT "./testdb"

通过这两个更改,我能够解决问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-12
    • 2017-03-06
    • 2018-11-17
    • 1970-01-01
    • 1970-01-01
    • 2021-07-19
    • 1970-01-01
    相关资源
    最近更新 更多