基于Centos7的Python3.7镜像构建

Dockerfile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
FROM centos:7

MAINTAINER linvaux <linvaux@outlook.com>

WORKDIR /opt

RUN sed -i "s/#baseurl/baseurl/g" /etc/yum.repos.d/CentOS-Base.repo && \
sed -i "s/mirrorlist=http/#mirrorlist=http/g" /etc/yum.repos.d/CentOS-Base.repo && \
sed -i "s@http://mirror.centos.org@https://repo.huaweicloud.com@g" /etc/yum.repos.d/CentOS-Base.repo && \
yum clean all && \
yum makecache && \
yum update -y

RUN yum install -y wget zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel libffi-devel gcc make

RUN wget https://mirrors.huaweicloud.com/python/3.7.8/Python-3.7.8.tgz && \
tar -vxf Python-3.7.8.tgz && \
mv Python-3.7.8 /usr/local/python378 && \
cd /usr/local/python378 && \
./configure --prefix=/usr/local/python378 --enable-loadable-sqlite-extensions --with-ssl &&\
make -j$(nproc) && \
make install -j$(nproc) && \
ln -s /usr/local/python378/bin/python3.7 /usr/bin/python3 && \
ln -s /usr/local/python378/bin/pip3 /usr/bin/pip3 && \
mkdir /root/.pip && \
echo "[global]" > /root/.pip/pip.conf && \
echo "index-url=https://pypi.douban.com/simple/" >> /root/.pip/pip.conf && \
echo "[install]" >> /root/.pip/pip.conf && \
echo "trusted-host=pypi.douban.com" >> /root/.pip/pip.conf
RUN rm -rf Python-3.7.8.tgz

构建命令

1
docker build -t centos-python378 .