简体   繁体   English

运行 docker 映像时返回“bin/bash: python: command not found”

[英]“bin/bash: python: command not found” returned when running docker image

Here is the docker run output:这是docker run output:

hausey@ubuntu:~/niso2-jxj934$ docker run niso2-jxj934
Test version: 15:59, Mar 24th 2020
Question 1: Evaluation of expression.
Command failed: /bin/bash -c "python /bin/jxj934.py  -question 1  -expr \"(ifleq (ifleq -1.11298616747 1.63619642199 (sub -1.11298616747 -1.11298616747) 1.7699684348) (add (exp -0.822479932786) 1.39992604386) (add -1.11298616747 (exp 0.385042309638)) 0.205973267133)\" -n 10 -x \"-0.168958230447 -0.131749160548 0.0971246476126 1.8706205565 -0.464122426299 2.35887369763 -0.375948313434 -0.613901105864 0.411326743135 -0.149276696072\"" Exit status: exited with code 127 stderr: /bin/bash: python: command not found

Here is the Dockerfile:这是 Dockerfile:

FROM pklehre/niso2020-lab2-msc
ADD jxj934.py /bin
CMD ["-username","jxj934", "-submission", "python /bin/jxj934.py"]

Here is check for python :这是检查python

hausey@ubuntu:~/niso2-jxj934$ which python
/usr/bin/python

Is that related to the PATH of python?这与 python 的路径有关吗?

Usually, it is related to the value of PATH but, specifically, that image only has python3 .通常,它与PATH的值有关,但具体来说,该图像只有python3 In other words, looking through the filesystem with换句话说,通过文件系统查看

find / -name -type f "python*"

Look for regular files named "python*" in //中查找名为“python*”的常规文件

There were only python3 results.只有python3结果。

...
/usr/bin/python3.8
/usr/bin/python3.7
...

A quick solution is to specify python3 in your CMD line ( python3 /bin/jxj934.py ).一个快速的解决方案是在您的 CMD 行 ( python3 /bin/jxj934.py ) 中指定python3 Another is to add a soft link ( ln -s /usr/bin/python /usr/bin/python3.8 ).另一种是添加软链接( ln -s /usr/bin/python /usr/bin/python3.8 )。 The best solution is to solve it using the package manager.最好的解决方案是使用 package 管理器来解决它。 Then again, that depends if you're in control of the Dockerfile + image.再说一次,这取决于您是否控制了Dockerfile + 图像。

When you queried which python , you did so on your local machine.当您查询which python时,您是在本地计算机上进行的。 The container runs in a different filesystem namespace than yours and with a completely different terminal.该容器在与您的不同的文件系统命名空间中运行,并且使用完全不同的终端。 The container will behave differently than your machine and any such investigations will yield relevant results only when run within the container.容器的行为与您的机器不同,任何此类调查只有在容器内运行时才会产生相关结果。

A little unrelated to your question but it might serve you.与您的问题有点无关,但它可能对您有用。
docker run has a --entrypoint option that allows you to override the image's entrypoint. docker run有一个--entrypoint选项,允许您覆盖图像的入口点。 You can ask for bash and explore the container.您可以询问 bash 并探索容器。

docker run --it --entrypoint=bash pklehre/niso2020-lab2-msc

Note that bash has to be in the $PATH.请注意, bash必须在 $PATH 中。

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

相关问题 /bin/sh python 运行 docker 基本映像时未找到错误 - /bin/sh python not found error when running docker base image (/ bin / bash:python3:找不到命令)在Matlab中通过系统命令运行python脚本时 - (/bin/bash: python3: command not found) When running python script through system command in Matlab Docker 镜像错误:/bin/sh: 1: python: not found - Docker image error: /bin/sh: 1: python: not found Docker 图像错误:“/bin/sh: 1: [python,: not found” - Docker image error: "/bin/sh: 1: [python,: not found" ```bash: xterm: command not found``` 运行 Python 时,Sublime Text 3 (Mac) - ```bash: xterm: command not found``` when running Python, Sublime Text 3 (Mac) 在run -it / bin / bash之外的docker容器中发出运行python脚本的问题 - Issue running python scripts in docker container outside of run -it /bin/bash 在某些IDE中找不到Mac OS X / bin / bash:python:命令 - Mac OS X /bin/bash: python: command not found in some IDE VSCode Python 运行命令错误:/bin/sh:python:找不到命令 - VSCode Python Running ommand Error: /bin/sh: python: command not found / bin / sh:1:python:运行docker容器时找不到 - /bin/sh: 1: python: not found while running docker container `/bin/sh: 1: python: not found` 当通过 docker 中的 cron 运行时 - `/bin/sh: 1: python: not found` when run via cron in docker
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM