拉取一个centos镜像

docker pull centos:7.6.1810

运行镜像;

docker run -d -t --name=centos centos:7.6.1810 bash 

将python的tar包复制到容器内;

python.tar包地址:https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz

docker cp Python-3.6.5.tgz centos:/

进入容器内

docker exec -it centos bash

#创建一个python目录
mkdir -p /export/servers/

#解压tar包
tar -zxvf Python-3.6.5.tgz -C /export/servers/
mv /export/servers/Python-3.6.5 /export/servers/python3.6
#下载一些python依赖,docker运行的centos是简化版
yum -y install openssl-devel bzip2-devel expat-devel gdbm-devel 
yum -y install readline-devel sqlite-devel gcc gcc-c++
yum -y install python-devel openldap-devel gettext gettext-common-devel gettext-devel
yum -y install automake autoconf libtool make
#进入python目录初始化python
cd /export/servers/python3.6
vi Modules/Setup.dist   #加入以下5行
_socket socketmodule.c timemodule.c
SSL=/usr/local/ssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto

#编译安装包,指定安装目录
./configure --with-ssl --prefix=/export/servers/python3.6
#编译
make
make install
#创建软连接
ln -s /export/servers/python3.6/bin/python3.6 /usr/bin/python3.6
ln -s /export/servers/python3.6/bin/pip3 /usr/bin/pip3.6

退出容器

exit

保存容器内容到一个新的基础镜像,可以用该镜像去制作别的镜像

docker commit centos zzx-python:3.6.5
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐