Saksham Paliwal
Saksham Paliwal

Reputation: 483

Docker: python has no installation candidate

I am trying to create a docker image from my docker file which has the following content:

FROM ubuntu:latest 
WORKDIR /app 
ADD . /app 
RUN apt-get update && apt-get install python -y 
CMD python /app/main.py 
LABEL color=red

which fails with the following error:

apt-get update && apt-get install python -y returned a non-zero code: 100 Error

So please help me in solving this error

Upvotes: 2

Views: 9910

Answers (1)

JRichardsz
JRichardsz

Reputation: 16505

Docker is just Linux. When some apt-get install acme fails, almost always is due to linux, not docker.

To find the solution the first step is to replicate the error in a clean or new linux machine.

Replicating your issue

To replicate your error in a clean linux I created an empty linux with: docker run -it ubuntu:latest

Then, inside the container I ran your apt-get update && apt-get install python -y. I got your error:

enter image description here

Solution

In this specifically case, since you are using FROM ubuntu:latest, in this year(2023) the latest ubuntu image don't allow by default python2

So, I if you try with apt-get install python3 -y, it will work. Finally your Dockerfile should be:

FROM ubuntu:latest 
WORKDIR /app 
ADD . /app 
RUN apt-get update && apt-get install python3 -y 
CMD python3 /app/main.py 
LABEL color=red

Older Python

If your code needs old python version, you should not use FROM ubuntu:latest because in the latest version of ubuntu, only python3 is allowed by default.

In case you need python2, you should research on internet one of these options:

Upvotes: 7

Related Questions