3

I am new to Docker so I am sorry for such an easy question.

I am building a docker container which is built on top of a image which is built on ubuntu:vivid image. When executing my script within the container I am getting an error:

exec: "python": executable file not found in $PATH

How can I solve this? When I try to run apt-get install python in my Docker file:

FROM my_image # based on ubuntu:vivid

RUN apt-get update && \
    apt-get install -y python3

ENV PATH /:$PATH

COPY file.py /

CMD ["python", "file.py", "-h"]

I get:

WARNING: The following packages cannot be authenticated!
  libexpat1 libffi6 libmagic1 libmpdec2 libssl1.0.0 libpython3.4-minimal
  mime-support libsqlite3-0 libpython3.4-stdlib python3.4-minimal
  python3-minimal python3.4 libpython3-stdlib dh-python python3 file
E: There are problems and -y was used without --force-yes
The command '/bin/sh -c apt-get update &&   apt-get install -y python3' returned a non-zero code: 100
make: *** [image] Error 1

EDIT: added Dockerfile content

6
  • apt-get install python or try to find python executable in ur machine and add to $PATH??? Commented Jan 28, 2016 at 4:09
  • Maybe you just use the official python docker image? Commented Jan 28, 2016 at 4:09
  • @cricket_007 Since mine is already based on a different image I can't do that Commented Jan 28, 2016 at 4:12
  • 1
    Please add your Dockerfile contents. Simply running apt-get from the container's shell isn't preferred Commented Jan 28, 2016 at 4:19
  • can you try apt-get -y update Commented Jan 28, 2016 at 5:19

2 Answers 2

2

You have similar issue with some Linux distribution: "Why am I getting authentication errors for packages from an Ubuntu repository?"

In all cases, the usual sequence of command to install new packages is:

RUN apt-get update -yq && apt-get install -yqq \
    git \
    python \
    ...

The OP Ela reports in the comments:

RUN apt-get update -y && apt-get install -y --force-yes \
    git \
    python \
    ...
Sign up to request clarification or add additional context in comments.

3 Comments

I tried your approach and then got Do you want to continue? [Y/n] Abort. The command '/bin/sh -c apt-get update && apt-get install - git python' returned a non-zero code: 1
@Ela OK, I have edited the answer accordingly, adding the parameters -yq and -yqq which should allow you to be in non-interactive mode.
This worked, the -yq for update is unnecessary. Moreover, this can also be achieved by install -y --force-yes, you can update your answer if you want to include that. I don't know which way is more desirable
1

You are installing python3 and then you use the executable of python, I had the same issue and I have resolved using python3.

Try changing your last line of your Dockerfile :

instead of CMD ["python", "file.py", "-h"]

try : CMD ["python3", "file.py", "-h"]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.