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
So please help me in solving this error
CodePudding user response:
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:
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:
- https://hub.docker.com/layers/python/library/python/2.7.18-slim-stretch/images/sha256-a0b3c65a15ba08138460de9fd2267b8dec30ed98407a0edac0adc0ccbe809cad?context=explore
- how do i setup only python 2.7 in docker container?
- https://github.com/Docker-Hub-frolvlad/docker-alpine-python2
CodePudding user response:
You should post all the output because maybe for some reason you use different apt sources than the official once.
However you need to give automatic consent to install:
apt-get install -y python
otherwise the command is waiting for you to approve.