在打包鏡像時,centos原生鏡像中python版本為2.7。如果我們的服務基于python3版本,則需要手動安裝。在安裝時,有一點需要注意的是:由于系統中某些服務以來python2.7版本,因此不要去刪除或修改系統中python的默認版本,否則會產生不可預知的后果。下面給出一個python3鏡像打包示例:
# base image
FROM centos:7.2.1511
# install related packages and python3
ENV ENVIRONMENT DOCKER_PROD
RUN cd / && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& yum makecache \
&& yum install -y wget aclocal automake autoconf make gcc gcc-c++ python-devel mysql-devel bzip2 libffi-devel epel-release\
&& wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz \
&& tar -xvf Python-3.7.0.tar.xz -C /usr/local/\
&& rm -rf Python-3.7.0.tar.xz \
&& cd /usr/local/Python-3.7.0 \
&& ./configure && make && make install \
&& yum clean all
# install related python packages
RUN yum install -y python-pip \
&& yum install -y python-setuptools \
&& pip3 install --upgrade pip -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com \
&& pip3 install setuptools==33.1.1 -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com \
&& pip3 install jieba==0.39 -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com \
&& pip3 install gensim==3.7.2 -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com \
&& pip3 install scipy==1.2.0 -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com \
&& pip3 install pandas==0.24.0 -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com \
&& pip3 install tensorflow==1.13.1 -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com \
在進行安裝時,使用
&&
連接多行的原因時:減少鏡像層數量,壓縮鏡像體積。
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
