1. 程式人生 > 其它 >Docker 操作:基於 Centos7 構建 python3 映象

Docker 操作:基於 Centos7 構建 python3 映象

技術標籤:Dockercentospythondocker

這裡有個坑,在 centos 中配了 python3 之後,yum 命令所依賴的 python2.7 會報錯,需要專門配一下

FROM centos:centos7

RUN yum update -y
RUN set -ex \
	&& yum -y install zlib-devel bzip2-devel libffi-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make wget \
	&& yum clean all \
	&& wget https://www.python.org/ftp/python/3.9.0/Python-3.9.0.tgz \
	&& mkdir /usr/local/python3 \
    && cp Python-3.9.0.tgz  /usr/local/python3/ 
RUN set -ex \
	&& cd /usr/local/python3 \
	&& tar -zxvf Python-3.9.0.tgz \
	&& cd Python-3.9.0 \
	&& ./configure prefix=/usr/local/python3 \
	&& make && make install \
	&& make clean \
    && yum install -y epel-release \
    && yum install -y python-pip
RUN set -ex \
    && mv /usr/bin/python /usr/bin/python27 \
    && mv /usr/bin/pip /usr/bin/pip-python2.7 \
	&& ln -s /usr/local/python3/bin/python3.9 /usr/bin/python \
    && ln -s /usr/local/python3/bin/pip3 /usr/bin/pip
RUN set -ex \
	&& python -V
# 這裡很重要,因為配了 py3 之後 2.7 就失效了,但是 yum 還是會用到 python2.7
RUN set -ex \
    && sed -i "s#/usr/bin/python#/usr/bin/python2.7#" /usr/bin/yum \
    && sed -i "s#/usr/bin/python#/usr/bin/python2.7#" /usr/libexec/urlgrabber-ext-down \
    && yum install -y deltarpm
RUN set -ex \
    && rm -rf /etc/localtime \
    && ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
    && yum install -y vim \
    && yum -y install cronie
RUN yum install kde-l10n-Chinese -y
RUN localedef -c -f UTF-8 -i zh_CN zh_CN.utf8
ENV LC_ALL zh_CN.UTF-8
ENV TZ Asia/Shanghai
ENV PATH /usr/local/python3/bin/:$PATH
RUN ln -sf /usr/share/zoneinfo/Asia/ShangHai /etc/localtime
RUN yum -y install net-tools redis-server vim ffmpeg netbase
RUN python -m pip install --upgrade pip
RUN pip --no-cache-dir install asgiref==3.3.1
RUN pip --no-cache-dir install branca==0.4.1
RUN pip --no-cache-dir install certifi==2020.12.5
RUN pip --no-cache-dir install chardet==4.0.0
RUN pip --no-cache-dir install Django==3.1.4
RUN pip --no-cache-dir install folium==0.11.0
RUN pip --no-cache-dir install idna==2.10
RUN pip --no-cache-dir install Jinja2==2.11.2
RUN pip --no-cache-dir install MarkupSafe==1.1.1
RUN pip --no-cache-dir install numpy==1.19.4
RUN pip --no-cache-dir install pandas==1.1.5
RUN pip --no-cache-dir install PyMySQL==0.10.1
RUN pip --no-cache-dir install python-dateutil==2.8.1
RUN pip --no-cache-dir install pytz==2020.4
RUN pip --no-cache-dir install requests==2.25.1
RUN pip --no-cache-dir install six==1.15.0
RUN pip --no-cache-dir install SQLAlchemy==1.3.21
RUN pip --no-cache-dir install sqlparse==0.4.1
RUN pip --no-cache-dir install urllib3==1.26.2
RUN pip --no-cache-dir install xlwt==1.3.0