1、下载源码包
#wget https://www.python.org/ftp/python/3.9.6/Python-3.9.6.tar.xz
2、Dockerfile:
FROM centos:centos7.9.2009
RUN yum -y install gcc make vim lsof wget tar bzip2 unzip vim-enhanced passwd sudo yum-utils hostname net-tools epel-release python-devel python-pip
ADD Python-3.9.6.tar.xz /opt/python396/
RUN cd /opt/python396/Python-3.9.6/ && mkdir -p /usr/local/python396 && ./configure prefix=/usr/local/python396 && \
make && make install && cd /usr/local/python396/bin/ && cp python3 /usr/bin/
3、 (构建镜像)
#docker build -t python3:3.9.6 -f Dockerfile . (构建镜像)
4、(测试版本)
#docker run -it --name python01 python3:3.9.6 python3 --version (测试版本)
