How do I install a Python 3.9 on top of amazon/aws-cli docker image which by default comes with python 2.7? What I have tried so far are these series of commands based off installation tutorials for installing Python 3 on Amazon Linux 2:
FROM amazon/aws-cli:latest
WORKDIR ./
COPY ./.aws ./root/.aws
COPY . .
RUN yum install gcc openssl-devel bzip2-devel libffi-devel -y
RUN yum install wget tar -y
RUN cd /opt
RUN wget https://www.python.org/ftp/python/3.9.6/Python-3.9.6.tgz
RUN tar xzf Python-3.9.6.tgz
RUN cd Python-3.9.6
RUN ./configure --enable-optimizations
RUN make altinstall
RUN rm -f /opt/Python-3.9.6.tgz
RUN ["python3", "-u", "app.py"]
But I am receiving this error:
[ ] Building 13.5s (14/19)
=> [internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 32B 0.0s
=> [internal] load .dockerignore 0.1s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/amazon/aws-cli:latest 12.2s
=> [auth] amazon/aws-cli:pull token for registry-1.docker.io 0.0s
=> [ 1/14] FROM docker.io/amazon/aws-cli:latest@sha256:fd66db7596251aada 0.0s
=> [internal] load build context 0.1s
=> => transferring context: 1.19kB 0.0s
=> CACHED [ 2/14] WORKDIR ./ 0.0s
=> CACHED [ 3/14] COPY ./.aws ./root/.aws 0.0s
=> CACHED [ 4/14] COPY . . 0.0s
=> CACHED [ 5/14] RUN yum install gcc openssl-devel bzip2-devel libffi-d 0.0s
=> CACHED [ 6/14] RUN yum install wget tar -y 0.0s
=> CACHED [ 7/14] RUN cd /opt 0.0s
=> CACHED [ 8/14] RUN wget https://www.python.org/ftp/python/3.9.6/Pytho 0.0s
=> ERROR [ 9/14] RUN tar xzf Python-3.9.6.tgz 1.0s
------
> [ 9/14] RUN tar xzf Python-3.9.6.tgz:
#14 0.959 tar (child): gzip: Cannot exec: No such file or directory
#14 0.959 tar (child): Error is not recoverable: exiting now
#14 0.961 tar: Child returned status 2
#14 0.961 tar: Error is not recoverable: exiting now
CodePudding user response:
You have to install gzip
and make
as well and use WORKDIR
:
FROM amazon/aws-cli:latest
WORKDIR ./
COPY ./.aws ./root/.aws
COPY . .
RUN yum install gcc openssl-devel bzip2-devel libffi-devel gzip make -y
RUN yum install wget tar -y
WORKDIR /opt
RUN wget https://www.python.org/ftp/python/3.9.6/Python-3.9.6.tgz
RUN tar xzf Python-3.9.6.tgz
WORKDIR /opt/Python-3.9.6
RUN ./configure --enable-optimizations
RUN make altinstall
RUN rm -f /opt/Python-3.9.6.tgz
RUN ["python3", "-u", "app.py"]