Ela
Ela

Reputation: 3412

Python in docker container

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

Upvotes: 3

Views: 9732

Answers (2)

Lorenzo Vitali
Lorenzo Vitali

Reputation: 340

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"]

Upvotes: 1

VonC
VonC

Reputation: 1328712

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 \
    ...

Upvotes: 2

Related Questions