简体   繁体   English

在 amazon/aws-cli docker 映像上安装 python 3.9

[英]Install python 3.9 on an amazon/aws-cli docker image

How do I install a Python 3.9 on top of amazon/aws-cli docker image which by default comes with python 2.7?如何在默认情况下带有 python 2.7 的 amazon/aws-cli docker 图像之上安装 Python 3.9? What I have tried so far are these series of commands based off installation tutorials for installing Python 3 on Amazon Linux 2:到目前为止,我所尝试的是基于安装教程的这些系列命令,用于在 Amazon Linux 2 上安装 Python 3:

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

You have to install gzip and make as well and use WORKDIR :您还必须安装gzipmake并使用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"]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM