Thursday, October 6, 2022

[SOLVED] Docker: python has no installation candidate

Issue

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


Solution

Docker is just Linux. When some apt-get install acme fails, you just need to try the exact command and or research the missing dependencies.

To replicate your error I ran: docker run -it ubuntu:latest and inside, I ran your apt-get update && apt-get install python -y. I got the error:

enter image description here

So, I tried with apt-get install python3 -y and it worked. 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 lastest version of ubuntu, only python3 is allowed.

Anyway if you need python2, you must research a lot on internet to get the exact steps to install python2 or use some ready to use docker images:



Answered By - JRichardsz
Answer Checked By - Candace Johnson (WPSolving Volunteer)