简体   繁体   English

没有这样的文件或目录,在 .net core 中运行控制台应用程序时无法在 docker 容器中找到 Python.exe

[英]No such file or directory, Unable to find Python.exe in docker container when running console app in .net core

I have a .net Core (version 2.2) console app that executes a python script via the command line.我有一个 .net Core(2.2 版)控制台应用程序,它通过命令行执行 python 脚本。 However, when i dockerize the project I get a file not found exception.但是,当我对项目进行 dockerize 时,我收到一个文件未找到异常。 From the error, the dockerized app is unable to locate python.exe and execute the python script.从错误来看,dockerized 应用程序无法定位 python.exe 并执行 python 脚本。

I have installed python from the dockerfile as shown.如图所示,我已经从 dockerfile 安装了 python。 Plus I have attempted to use command " docker exec -it /bin/bash " to find the python.exe and change the path given in the .Net Core program.另外,我尝试使用命令“docker exec -it /bin/bash”来查找 python.exe 并更改 .Net Core 程序中给出的路径。

.Net-Core code: .Net 核心代码:

System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "python.exe";
startInfo.Arguments = "myScript.py";
process.StartInfo = startInfo;
process.Start();

python code:蟒蛇代码:

print("Hello c#")

dockerfile:码头档案:

FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443


FROM python:3.7
FROM microsoft/dotnet:2.2-sdk AS build
ENV http_proxy=http://XXX.XXX.XX.XX:XXXX
ENV https_proxy=http://XXX.XXX.XX.XX:XXXX
WORKDIR /src
COPY ["myCode/MyProject.csproj"]
RUN dotnet restore "myCode/MyProject.csproj"
COPY . .
WORKDIR "/src/myCode"
RUN dotnet build "MyProject.csproj" -c Release -o /app
ENV http_proxy=
ENV https_proxy=


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

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

Expected Output: " Hello C# " from in console.预期输出:来自控制台的“Hello C#”。

I had a similar issue and was getting the same error as you.我遇到了类似的问题,并且遇到了与您相同的错误。 I just changed the file name like StartInfo.FileName = "python3" and then it started working.我只是更改了文件名,如StartInfo.FileName = "python3"然后它开始工作了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 .Net Core 控制台应用程序未在 Docker 容器中运行 - .Net Core Console App not running in Docker container 在 Linux 应用服务上的 docker 容器中运行.Net Core 控制台应用 - Running .Net Core console app in docker container on Linux App Service 运行 dot net core 控制台的映像时如何在启动时将参数传递给 docker 容器 - How to pass arguments to a docker container at start when running an image of dot net core console 如何从在 Linux(docker 容器)上运行的 c#.net 核心在远程 Windows 网络路径上运行 .exe - How to run .exe on remote windows network path from c# .net core running on Linux (docker container) 使 .net 核心控制台应用程序成为单个 .exe - Make .net core console app a single .exe 从控制台运行dotnet core应用程序时无法解决依赖关系 - Unable to resolve dependency when running dotnet core app from console 如何获取 .Net Core 控制台应用程序的 .exe 文件所在目录的路径? - How to get the path of the directory where the .exe file for a .Net Core console application is located? 在 Docker 中运行 ASP.NET Core 应用程序时丢失文件:如何在容器运行时显示文件? - Missing files when running ASP.NET Core application in Docker: How to display files when the container is running? Docker 容器找不到 .NET 框架 - Docker container unable to find .NET framework 将 .NET Core 控制台应用程序作为服务运行,还是重做? - Running .NET Core console app as a service, or redo?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM