J.H J
J.H J

Reputation: 53

"bin/bash: python: command not found" returned when running docker image

Here is the 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:

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

Here is check for python:

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

Is that related to the PATH of python?

Upvotes: 5

Views: 13748

Answers (1)

edd
edd

Reputation: 1417

Usually, it is related to the value of PATH but, specifically, that image only has python3. In other words, looking through the filesystem with

find / -name -type f "python*"

Look for regular files named "python*" in /

There were only python3 results.

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

A quick solution is to specify python3 in your CMD line (python3 /bin/jxj934.py). Another is to add a soft link (ln -s /usr/bin/python /usr/bin/python3.8). The best solution is to solve it using the package manager. Then again, that depends if you're in control of the Dockerfile + image.

When you queried which python, you did so on your local machine. 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. You can ask for bash and explore the container.

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

Note that bash has to be in the $PATH.

Upvotes: 10

Related Questions