比官方镜像体积还小的基于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" ]
相关推荐
南猿北者2 小时前
docker容器
docker·容器
二十雨辰2 小时前
[linux]docker基础
linux·运维·docker
time never ceases3 小时前
使用docker方式进行Oracle数据库的物理迁移(helowin/oracle_11g)
数据库·docker·oracle
MonkeyKing_sunyuhua5 小时前
ubuntu22.04 docker-compose安装postgresql数据库
数据库·docker·postgresql
追风林5 小时前
mac m1 docker本地部署canal 监听mysql的binglog日志
java·docker·mac
€☞扫地僧☜€6 小时前
docker 拉取MySQL8.0镜像以及安装
运维·数据库·docker·容器
茶馆大橘6 小时前
微服务系列六:分布式事务与seata
分布式·docker·微服务·nacos·seata·springcloud
全能全知者7 小时前
docker快速安装与配置mongoDB
mongodb·docker·容器
阿尔帕兹9 小时前
构建 HTTP 服务端与 Docker 镜像:从开发到测试
网络协议·http·docker
ZHOU西口11 小时前
微服务实战系列之玩转Docker(十八)
分布式·docker·云原生·架构·数据安全·etcd·rbac