Python3.11编译安装RuntimeDocker镜像

13 篇文章 0 订阅
3 篇文章 0 订阅

title: 0225-Python3.11编译安装RuntimeDocker镜像
tags:

  • Python3.11
  • Docker镜像
  • sshd
  • openEuler
    date: 2023-08-02 18:33:48

一、基础Docker镜像下载

openEuler的Docker基础镜像下载地址:

  1. openEuler-22.03-LTS-SP2/x86_64
  2. openEuler-22.03-LTS-SP2/aarch64
  3. openEuler-23.03/x86_64

openEuler的官网

openEuler 22.03 LTS SP2

二. 下载python源码

python-3.11.4

三、基础镜像导入

docker images

docker load < .\openeuler_python\openEuler-22.03-LTS-SP2-docker.x86_64.tar.xz
docker tag openeuler-22.03-lts-sp2:latest openeuler:22.03.lts.sp2
docker rmi openeuler-22.03-lts-sp2:latest

docker load < .\openeuler_python\openEuler-23.03-docker.x86_64.tar.xz
docker tag openeuler-23.03:latest openeuler:23.03
docker rmi openeuler-23.03:latest

docker run -it openeuler:22.03.lts.sp2 /bin/bash

四、python编译

  1. 软件安装:
yum -y groupinstall "Development tools"
yum -y install wget

yum -y install zlib zlib-devel bzip2-devel  openssl-devel 
yum -y install ncurses-devel sqlite-devel readline-devel 
yum -y install tk-devel gdbm-devel wget  xz-devel
yum -y install gcc kernel-devel make bzip2 libffi libffi-devel 
yum -y install expat-devel e2fsprogs-devel libuuid-devel tcl
yum -y install gdbm-devel tcl-devel tk-devel uuid-devel 

  1. openssl编译安装
yum -y remove openssl
cd /opt

export ssl_ver=3.8.0
wget http://ftp.jaist.ac.jp/pub/OpenBSD/LibreSSL/libressl-$ssl_ver.tar.gz
tar xzvf libressl-$ssl_ver.tar.gz
cd libressl-$ssl_ver
./configure --prefix=/usr/local/ssl 
make
make install
  1. python编译安装
export py_ver=3.11.4
wget https://www.python.org/ftp/python/${py_ver}/Python-${py_ver}.tgz
tar xzvf Python-${py_ver}.tgz
cd Python-${py_ver}

./configure --prefix=/usr/local/python${py_ver//.} --enable-optimizations --with-uuid=ossp CFLAGS=-fPIC  --enable-shared
make -j4
make install

ln -s /usr/local/python${py_ver//.}/bin/python${py_ver%.*} /usr/bin/python${py_ver} 
ln -s /usr/local/python${py_ver//.}/bin/python${py_ver%.*} /usr/bin/python${py_ver//.} 
ln -s /usr/local/python${py_ver//.}/bin/pip${py_ver%.*} /usr/bin/pip${py_ver}
ln -s /usr/local/python${py_ver//.}/bin/pip${py_ver%.*} /usr/bin/pip${py_ver//.}
# sudo ln -s /usr/local/python${py_ver//.}/bin/python${py_ver%.*} /usr/bin/python${py_ver%.*}
# sudo ln -s /usr/local/python${py_ver//.}/bin/pip${py_ver%.*} /usr/bin/pip${py_ver%.*}

# python3: error while loading shared libraries: libpython3.7m.so.1.0: cannot open shared object file: No such file or directory
echo /usr/local/python${py_ver//.}/lib > ./python${py_ver//.}.conf
mv ./python${py_ver//.}.conf /etc/ld.so.conf.d/
ldconfig -v

五、形成dockerfile文件

  1. 文件open_euler_python.dockerfile内容如下:
# open_euler_python.dockerfile
# Version 1.0.0
# export ssl_ver=3.8.0
# wget http://ftp.jaist.ac.jp/pub/OpenBSD/LibreSSL/libressl-$ssl_ver.tar.gz
# export py_ver=3.11.4
# wget https://www.python.org/ftp/python/${py_ver}/Python-${py_ver}.tgz
# set 
# build cmd: docker build --target dev_image -t open-euler-py-dev:22.03.3114 -f open_euler_python.dockerfile .
# build cmd: docker build -t open-euler-py:22.03.3114 -f open_euler_python.dockerfile .

ARG openEulerVer=22.03.lts.sp2
FROM openeuler:${openEulerVer} as dev_image
LABEL MAINTAINER="zhongmb@139.com"

ARG openEulerVer=22.03.lts.sp2
ARG pyVer=3.11.4
ARG sslVer=3.8.0

# COPY ./libressl-${sslVer}.tar.gz ./
# COPY ./Python-${pyVer}.tgz ./

RUN yum -y groupinstall "Development tools" && \
    yum -y install zlib zlib-devel bzip2-devel  openssl-devel  && \
    yum -y install ncurses-devel sqlite-devel readline-devel   && \
    yum -y install tk-devel gdbm-devel wget  xz-devel && \
    yum -y install gcc kernel-devel make bzip2 libffi libffi-devel  && \
    yum -y install expat-devel e2fsprogs-devel libuuid-devel tcl && \
    yum -y install gdbm-devel tcl-devel tk-devel uuid-devel
    
RUN yum -y remove openssl && \ 
    export ssl_ver=${sslVer}  && \
    wget http://ftp.jaist.ac.jp/pub/OpenBSD/LibreSSL/libressl-$ssl_ver.tar.gz && \
    tar xzvf libressl-$ssl_ver.tar.gz && \
    rm libressl-$ssl_ver.tar.gz && \
    cd libressl-$ssl_ver && \
    ./configure --prefix=/usr/local/ssl  && \
    make -j4 && \
    make install && \
    ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl  && \
    ln -s /usr/local/ssl/include/openssl /usr/include/openssl  && \
    echo /usr/local/ssl/lib > /etc/ld.so.conf.d/libressl-$ssl_ver.conf  && \
    ldconfig -v && \
    cd .. && rm -fr ./libressl-$ssl_ver
    
RUN export py_ver=${pyVer} && \
    wget https://www.python.org/ftp/python/${py_ver}/Python-${py_ver}.tgz && \
    tar xzvf Python-$py_ver.tgz && \
    rm Python-$py_ver.tgz && \
    cd Python-$py_ver && \
    ./configure --prefix=/usr/local/python$py_ver --enable-optimizations --with-uuid=ossp CFLAGS=-fPIC  --enable-shared --with-openssl=/usr/local/ssl && \
    make -j4 && \
    make install && \
    ln -s /usr/local/python$py_ver/bin/python${py_ver%.*} /usr/bin/python$py_ver && \
    ln -s /usr/local/python$py_ver/bin/python${py_ver%.*} /usr/bin/python${py_ver//.} && \
    ln -s /usr/local/python$py_ver/bin/pip${py_ver%.*} /usr/bin/pip$py_ver && \
    ln -s /usr/local/python$py_ver/bin/pip${py_ver%.*} /usr/bin/pip${py_ver//.} && \
    ln -s /usr/local/python$py_ver/bin/python${py_ver%.*} /usr/local/bin/python3 && \
    ln -s /usr/local/python$py_ver/bin/pip${py_ver%.*} /usr/local/bin/pip3 && \
    echo /usr/local/python$py_ver/lib > /etc/ld.so.conf.d/python-$py_ver.conf  && \
    ldconfig -v && \
    cd .. && rm -fr Python-$py_ver
    
RUN export py_ver=${pyVer} && \
    /usr/bin/python$py_ver -m pip install --upgrade --index-url=https://mirrors.huaweicloud.com/repository/pypi/simple --trusted-host=mirrors.huaweicloud.com pip && \
    /usr/bin/pip$py_ver install --upgrade --index-url=https://mirrors.huaweicloud.com/repository/pypi/simple --trusted-host=mirrors.huaweicloud.com setuptools
    
RUN yum clean all && rm -fr /tmp/* && rm -fr /var/tmp/* && rm -fr /var/cache/*



ARG openEulerVer=22.03.lts.sp2
FROM openeuler:${openEulerVer} as runtime_image
LABEL MAINTAINER="zhongmb@139.com"

ARG openEulerVer=22.03.lts.sp2
ARG pyVer=3.11.4
ARG sslVer=3.8.0

ENV py_ver=${pyVer}
COPY --from=dev_image /usr/local/ssl /usr/local/ssl
COPY --from=dev_image /usr/local/python$py_ver /usr/local/python$py_ver

RUN export ssl_ver=${sslVer}  && \
    echo /usr/local/ssl/lib > /etc/ld.so.conf.d/libressl-$ssl_ver.conf  && \
    ldconfig -v && \
    ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl  && \
    ln -s /usr/local/ssl/include/openssl /usr/include/openssl  && \
    export py_ver=${pyVer} && \
    ln -s /usr/local/python$py_ver/bin/python${py_ver%.*} /usr/bin/python$py_ver && \
    ln -s /usr/local/python$py_ver/bin/python${py_ver%.*} /usr/bin/python${py_ver//.} && \
    ln -s /usr/local/python$py_ver/bin/pip${py_ver%.*} /usr/bin/pip$py_ver && \
    ln -s /usr/local/python$py_ver/bin/pip${py_ver%.*} /usr/bin/pip${py_ver//.} && \
    echo /usr/local/python$py_ver/lib > /etc/ld.so.conf.d/python-$py_ver.conf  && \
    ldconfig -v
  1. 生成镜像:
cd openeuler_python
docker build -t open-euler-py:22.03.3114 -f open_euler_python.dockerfile .

六、导出含有python3.11.4运行环境的镜像,并压缩

  1. 导出镜像:
docker save  open-euler-py:22.03.3114  > openEuler-22.03-LTS-SP2-py3.11.4.tar
docker save  open-euler-py-dev:22.03.3114  > openEuler-22.03-LTS-SP2-py3.11.4-dev.tar
  1. 拷贝到容器中
docker cp openEuler-22.03-LTS-SP2-py3.11.4-dev.tar 54b31ad2f905:/opt/
docker cp openEuler-22.03-LTS-SP2-py3.11.4.tar 54b31ad2f905:/opt/
  1. 在容器中使用xz压缩
yum install xz

xz openEuler-22.03-LTS-SP2-py3.11.4.tar
xz openEuler-22.03-LTS-SP2-py3.11.4-dev.tar
  1. 从容器中导出
docker cp 54b31ad2f905:/opt/openEuler-22.03-LTS-SP2-py3.11.4-dev.tar.xz .\
docker cp 54b31ad2f905:/opt/openEuler-22.03-LTS-SP2-py3.11.4.tar.xz .\

七、python换源

mkdir ~/.pip
cat > ~/.pip/pip.conf << EOF
[global]
index-url = http://mirrors.huaweicloud.com/repository/pypi/simple
trusted-host = mirrors.huaweicloud.com
timeout = 120
EOF

© 著作权归作者所有

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

mengyoufengyu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值