python - docker run <image> 错误 : Can't find python executable to run

标签 python linux windows docker dockerfile

我在带有 Linux 容器选项的 Win10 上运行社区版 Docker(版本 18.03.1-ce-win65 (17513))。我在 Windows 上本地使用 docker 构建一个图像,并将其推送到 Portus,最后访问它以使用 Putty 从运行 Linux 的 HPC 运行。好吧,事实证明,由于以下错误,我无法运行创建的图像的实例:

python: can't open file './Turn.py': [Errno 2] No such file or directory

这是我用来构建镜像的 Dockerfile

FROM python:3.6
LABEL version="1.0"
LABEL build_date="xxx"
LABEL description="xxx"
COPY requirements.txt /
RUN pip install -r requirements.txt
ENV PYTHONIOENCODING UTF-8
# Set the default directory where CMD will execute on HPC
WORKDIR /turn
COPY Turn.py /Turn.py
CMD ["python", "./Turn.py"]

构建过程成功完成,如下所示:

Sending build context to Docker daemon   12.8kB
Step 1/13 : FROM python:3.6
 ---> 5f87764f9df0
Step 2/13 : LABEL maintainer="xxx"
 ---> Using cache
 ---> 71cd96de7015
Step 3/13 : LABEL version="1.0"
 ---> Using cache
 ---> 2fc5cdab38a9
Step 4/13 : LABEL build_date="xxx"
 ---> Using cache
 ---> ae488b87a931
Step 5/13 : LABEL description="xxx"
 ---> Using cache
 ---> cb11a0cf08a2
Step 6/13 : COPY requirements.txt /
 ---> Using cache
 ---> 5ec08f42d1f7
Step 7/13 : RUN pip install -r requirements.txt
 ---> Using cache
 ---> dfa45323647a
Step 8/13 : ENV PYTHONIOENCODING UTF-8
 ---> Using cache
 ---> 733907694a25
Step 9/13 : ENV http_proxy="http://xxx"
 ---> Using cache
 ---> 9b0ba73057ae
Step 10/13 : ENV https_proxy="https://xxx"
 ---> Using cache
 ---> e1ea75915df8
Step 11/13 : WORKDIR /turn
 ---> Using cache
 ---> a8b8ad69d82c
Step 12/13 : COPY Turn.py /Turn.py
 ---> Using cache
 ---> 9f9cb068c16b
Step 13/13 : CMD ["python", "./Turn.py"]
 ---> Using cache
 ---> a7f10949e521
Successfully built a7f10949e521
Successfully tagged turn:latest

SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.

我正在尝试使用以下命令运行此图像:

f@hpclogin1:~> docker run hpcdocker.hpc.xxx.com:5000/namespace/turn:latest 

python: can't open file './Turn.py': [Errno 2] No such file or directory

最佳答案

这应该是一个简单的路径问题。 请注意您是如何在 ./turn.py 上调用 python 的?这意味着您将假设它是当前目录的子目录,根据您的入口点,它不一定是您将其复制到的根文件夹。

简单地改变你的电话 CMD ["python", "./Turn.py"] CMD ["python", "/Turn.py"] 应该解决问题。

关于python - docker run <image> 错误 : Can't find python executable to run,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51166581/

相关文章:

python - 将 <m8[ns] 转换为整数

python - Conda/Spyder环境错误-js不允许加载本地资源

python - 如何在没有任何索引的情况下合并两个数据帧

c - 为什么不应该使用 ftime?

c++ - 可移植应用程序需要非可移植 dll

python - count() 的奇怪执行时间

linux - 内部调用 Linux 命令并将输出保存到文件的 Perl 脚本?

linux - 将 "mail -a"与 $Sender var 一起使用

windows - 合并\加入三个 FFMPEG 命令(Drawtext/-filter_complex overlay/anullsrc=channel_layout)

windows - gl3w 编译错误 : invalid conversion from 'PROC ... to void*'