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

标签 python python-3.x amazon-web-services docker

如何在 amazon/aws-cli docker 镜像之上安装 Python 3.9,默认情况下 python 2.7 附带?到目前为止,我所尝试的是基于在 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"]

但是我收到这个错误:

[+] 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

最佳答案

您还必须安装 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"]

关于python - 在 amazon/aws-cli docker 镜像上安装 python 3.9,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71135651/

相关文章:

python - 没有 IN 运算符的列表如何值

python - 如何在python中找到给定范围内给定函数的最大值?

python - 我可以在多处理池星图方法中传递队列对象吗

amazon-web-services - 无法访问托管在 AWS 私有(private)子网中的 ElasticSearch 服务器

python - MatLab 和 numpy 中 Hermitian 矩阵特征值的差异

Python: os.environ.get ('SSH_ORIGINAL_COMMAND' ) 返回 None

arrays - 在Numpy Array中转换Python get request(jpg content)的响应

python-3.x - 如何使用python从S3存储桶下载所有文件而不考虑文件 key

mysql - 最佳实践 : How to use Terraform to create custom MySQL (RDS) user via CI?

python - pandas 中的高效链合并