比官方镜像体积还小的基于Anolis OS8.6的Python3.8.8的编译安装Dockerfile

本次编译安装解决了安装3.8.8编译安装过程中的所有报错,同时,OpenSSL升级至3.0.14、内置Git,支持IPv6,Python环境同时预安装httpx和boto3模块。

dockerfile 复制代码
FROM openanolis/anolisos:8.6 as PYTHON

ARG PYTHON_VERSION="3.8.8"
ARG OPENSSL_VERSION="3.0.14"

# https://www.python.org/ftp/python/3.8.8/Python-3.8.8.tar.xz
ADD [ "Python-${PYTHON_VERSION}.tar.xz", "/" ]
# https://www.openssl.org/source/openssl-3.0.14.tar.gz
ADD [ "openssl-${OPENSSL_VERSION}.tar.gz", "/" ]

ENV LC_ALL="C"

RUN set -eu; \
    yum install -y gcc \
                   make \
                   perl \
                   zlib-devel \
                   bzip2-devel \
                   ncurses-devel \
                   sqlite-devel \
                   readline-devel \
                   tk-devel \
                   gdbm-devel \
                   xz-devel \
                   libffi-devel \
                   uuid-devel \
                   perl-IPC-Cmd \
                   libnsl2-devel

RUN set -eu; \
    cd /openssl-${OPENSSL_VERSION}; \
    ./config --prefix=/usr/local; \
    make -j `nproc`; \
    make install; \
    make clean; \
    echo "/usr/local/lib64">/etc/ld.so.conf.d/ld.local.conf; \
    echo "/usr/local/lib">>/etc/ld.so.conf.d/ld.local.conf; \
    ldconfig; \
    cd /Python-${PYTHON_VERSION}; \
    ./configure \
        --enable-optimizations \
        --with-lto \
        --enable-shared \
        --enable-ipv6 \
        --enable-loadable-sqlite-extensions \
        --with-ssl-default-suites=openssl \
        --enable-option-checking=fatal \
        --with-system-expat \
        --with-openssl=/usr/local \
        --prefix=/usr/local; \
    make -j `nproc`; \
    make install; \
    make clean; \
    ldconfig; \
    yum clean all

FROM openanolis/anolisos:8.6 as OS

ARG PYTHON_VERSION="3.8.8"

COPY \
    --from=PYTHON /usr/local /usr/local

ENV TZ="Asia/Shanghai" \
    LANG="zh_CN.UTF-8" \
    LC_ALL="C"

RUN set -eu; \
    yum install -y glibc-langpack-zh \
                   zlib-devel \
                   bzip2-devel \
                   ncurses-devel \
                   sqlite-devel \
                   readline-devel \
                   tk-devel \
                   gdbm-devel \
                   xz-devel \
                   libffi-devel \
                   uuid-devel \
                   libnsl2-devel \
                   git; \
    yum clean all

RUN set -eu; \
    ln -sf /usr/local/bin/python3 /usr/bin/python3; \
    ln -sf /usr/local/bin/python${PYTHON_VERSION} /usr/bin/python3; \
    ln -sf /usr/local/bin/python3 /usr/bin/python; \
    ln -sf /usr/local/bin/pip${PYTHON_VERSION} /usr/bin/pip3; \
    echo "/usr/local/lib">/etc/ld.so.conf.d/ld.local.conf; \
    echo "/usr/local/lib64">>/etc/ld.so.conf.d/ld.local.conf; \
    ldconfig; \
    python3 -m pip install --upgrade pip; \
    python3 -c "import sysconfig; print(sysconfig.get_config_var('CONFIG_ARGS'))"; \
    pip install boto3 httpx; \
    pip cache purge; \
    rm -rf /var/cache/yum/*; \
    rm -rf /root/.cache; \
    rm -rf /tmp/*

FROM openanolis/anolisos:8.6 as FIN

COPY \
    --from=OS /usr /usr
COPY \
    --from=OS /etc /etc

FROM scratch

COPY \
    --from=FIN / /

LABEL \
    AUTHOR="IVAN DU" \
    DATE="2024-06-21" \
    VERSION="1.0.0" \
    PYTHON_VERSION="3.8.8"

ENV TZ="Asia/Shanghai" \
    LANG="zh_CN.UTF-8" \
    LC_ALL="C"

CMD [ "/usr/bin/python" ]
相关推荐
胖毁青春,瘦解百病1 小时前
Docker镜像源设置不生效问题排查
docker·容器
嘤嘤怪呆呆狗2 小时前
【开发问题记录】使用 Docker+Jenkins+Jenkins + gitee 实现自动化部署前端项目 CI/CD(centos7为例)
前端·vue.js·ci/cd·docker·gitee·自动化·jenkins
Carry_NJ4 小时前
docker-compose样例
运维·docker·容器
梁萌9 小时前
Linux安装Docker
linux·运维·docker·helloworld·容器化部署
翱翔-蓝天9 小时前
在 CentOS 系统上安装 ClickHouse
运维·docker·容器
cdg==吃蛋糕12 小时前
docker代理配置
docker·容器·eureka
web1350858863513 小时前
使用docker compose安装gitlab
docker·容器·gitlab
IT机器猫13 小时前
Docker完整技术汇总
运维·docker·容器
董健正13 小时前
Docker安装
docker·容器·docker-compose
gs8014014 小时前
替换 Docker.io 的 Harbor 安全部署指南:域名与 IP 双支持的镜像管理解决方案
docker·harbor