简体   繁体   中英

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. However, when i dockerize the project I get a file not found exception. From the error, the dockerized app is unable to locate python.exe and execute the python script.

I have installed python from the dockerfile as shown. 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.

.Net-Core code:

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM