From ea0f84abb38b0c61c3e122345dc5c1426994f0cd Mon Sep 17 00:00:00 2001 From: Odboy Date: Sat, 26 Jul 2025 21:46:53 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20System=20=E9=95=9C=E5=83=8F?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E5=A4=9A=E9=98=B6=E6=AE=B5=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=EF=BC=8CPython=20=E7=BC=96=E8=AF=91=E4=BA=A7=E7=89=A9=E6=8B=B7?= =?UTF-8?q?=E8=B4=9D=E8=87=B3=E8=BF=90=E8=A1=8C=E9=98=B6=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - builder 阶段安装编译依赖并编译安装 Python 3.10.0 - 运行阶段仅 update 系统、拷贝 /usr/local/python3 与 pip.conf - 先创建 ~/.pip 目录,避免 COPY 将其当作文件 --- Other/nginx-tengine-3.1.0/nginx.conf | 0 System/Dockerfile | 47 +++++++++++++++++++++++----- System/pip.conf | 5 +++ 3 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 Other/nginx-tengine-3.1.0/nginx.conf create mode 100644 System/pip.conf diff --git a/Other/nginx-tengine-3.1.0/nginx.conf b/Other/nginx-tengine-3.1.0/nginx.conf new file mode 100644 index 0000000..e69de29 diff --git a/System/Dockerfile b/System/Dockerfile index 4d9e7a6..0d3cc2c 100644 --- a/System/Dockerfile +++ b/System/Dockerfile @@ -1,13 +1,46 @@ +# 编译阶段:仅用于构建 Python,构建工具链不进入最终镜像 +FROM alibaba-cloud-linux-3-registry.cn-hangzhou.cr.aliyuncs.com/alinux3/alinux3:220901.1 AS builder +ENV TimeZone=Asia/Shanghai +ENV PYTHON_HOME=/usr/local/python3 +WORKDIR /home/admin + +ADD https://www.python.org/ftp/python/3.10.0/Python-3.10.0.tgz ./ +RUN yum install \ + libffi-devel \ + zlib-devel \ + bzip2-devel \ + openssl-devel \ + ncurses-devel \ + sqlite-devel \ + readline-devel \ + tk-devel \ + gdbm-devel \ + libpcap-devel \ + xz-devel \ + make \ + patch \ + gcc \ + tar -y; \ + tar -xvf Python-3.10.0.tgz; \ + cd Python-3.10.0; \ + ./configure --prefix=/usr/local/python3; \ + make && make install; \ + python3 -V + +# 运行阶段:仅保留 Python 运行时 FROM alibaba-cloud-linux-3-registry.cn-hangzhou.cr.aliyuncs.com/alinux3/alinux3:220901.1 LABEL MAINTAINER="tianjun@odboy.cn" ENV TimeZone=Asia/Shanghai +ENV PYTHON_HOME=/usr/local/python3 +ENV PATH="${PYTHON_HOME}/bin:$PATH" WORKDIR /home/admin -#RUN ln -snf /usr/share/zoneinfo/$TimeZone /etc/localtime && echo $TimeZone > /etc/timezone; \ -# sed -i 's/mirrors.cloud.aliyuncs.com/mirrors.aliyun.com/' /etc/yum.repos.d/*.repo; \ -# yum install \ -# tar \ -# wget \ -# net-tools \ -# bind-utils -y; + RUN yum update -y && yum clean all; \ rm -rf /usr/lib/python3.6; + +COPY --from=builder /usr/local/python3 /usr/local/python3 +# COPY 的目标目录不存在时会当成文件创建,需先建好 ~/.pip +RUN mkdir ~/.pip +COPY pip.conf ~/.pip/ + +RUN python3 -V; pip3 -V diff --git a/System/pip.conf b/System/pip.conf new file mode 100644 index 0000000..4591cae --- /dev/null +++ b/System/pip.conf @@ -0,0 +1,5 @@ +[global] +index-url = https://mirrors.aliyun.com/pypi/simple + +[install] +trusted-host = mirrors.aliyun.com \ No newline at end of file