title: 0225-Python3.11编译安装RuntimeDocker镜像
tags:
- Python3.11
- Docker镜像
- sshd
- openEuler
date: 2023-08-02 18:33:48
一、基础Docker镜像下载
openEuler的Docker基础镜像下载地址:
openEuler的官网
二. 下载python源码
三、基础镜像导入
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编译
- 软件安装:
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
- 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
- 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文件
- 文件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
- 生成镜像:
cd openeuler_python
docker build -t open-euler-py:22.03.3114 -f open_euler_python.dockerfile .
六、导出含有python3.11.4运行环境的镜像,并压缩
- 导出镜像:
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
- 拷贝到容器中
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/
- 在容器中使用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
- 从容器中导出
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
© 著作权归作者所有