【问题标题】:docker run: Could not execute because the specified command or file was not founddocker run:无法执行,因为找不到指定的命令或文件
【发布时间】:2020-05-09 10:19:32
【问题描述】:

我为 .net 核心控制台应用程序制作了一个 docker 文件:

FROM mcr.microsoft.com/dotnet/core/sdk:3.1
LABEL author="some name"
LABEL description="some description"
ENTRYPOINT [ "dotnet", "L1_1_Console.dll" ]

并从中创建了一个名为“labo1_1_console_image”的图像

当我尝试使用此命令运行此映像时:

docker run --rm -it labo1_1_console_image

我收到此错误:

Could not execute because the specified command or file was not found.
Possible reasons for this include:
  * You misspelled a built-in dotnet command.
  * You intended to execute a .NET Core program, but dotnet-L1_1_Console.dll does not exist.
  * You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.

我认为问题是第二个问题(我不确定),但我不知道如何解决这个问题,我的 L1_1_Console.dll 文件分别位于 docker 文件位置 /bin/Release/netcoreapp3.1(我也有发布这里的文件夹与相同的文件)

更新:

我将 docker 文件更改为:

FROM mcr.microsoft.com/dotnet/core/sdk:3.1
LABEL author="somename"
LABEL description=" some description"
ADD bin/Release/netcoreapp3.1/publish/L1_1_Console.dll L1_1_Console.dll
ADD bin/Release/netcoreapp3.1/publish/L1_1_Console.runtimeconfig.json L1_1_Console.runtimeconfig.json
ENTRYPOINT [ "dotnet", "L1_1_Console.dll" ]

【问题讨论】:

    标签: c# docker .net-core console-application


    【解决方案1】:

    将您的 Dockerfile 更改为

    FROM mcr.microsoft.com/dotnet/core/sdk:3.1
    LABEL author="some name"
    LABEL description="some description"
    ADD bin/Release/netcoreapp3.1/L1_1_Console.dll L1_1_Console.dll
    ENTRYPOINT [ "dotnet", "L1_1_Console.dll" ]
    

    入口点只能看到你的docker镜像中的文件(除非你挂载了一个外部卷),所以你需要手动将你的dll文件添加到镜像中才能运行它。

    【讨论】:

    • 谢谢这帮了很大的忙,我改变了一些东西,我把它改成了发布文件夹,还添加了 runtimeconfig.json 文件来修复另一个错误
    猜你喜欢
    • 1970-01-01
    • 2020-05-18
    • 1970-01-01
    • 2020-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-27
    • 1970-01-01
    相关资源
    最近更新 更多