如何在 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
最佳答案
您还必须安装 gzip
和 make
并使用 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/