1. 程式人生 > 實用技巧 >使用dockerfile基於centos構建python3映象

使用dockerfile基於centos構建python3映象

dockerfile

FROM centos:7

RUN rm /bin/sh && ln -s /bin/bash /bin/sh
# centos設定環境變數會報/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
ENV LANG zh_CN.UTF-8
ENV LC_ALL zh_CN.UTF-8
# 所以需要在設定環境變數之後使用localedef建立一個字符集
RUN localedef -c -f UTF-8 -i zh_CN zh_CN.utf8

RUN yum update -y && yum -y install wget curl unzip zip gcc make lsof zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel libffi-devel libpcap-devel xz-devel git make libaio libnsl

RUN mkdir ~/.pyenv
RUN git clone git://github.com/yyuu/pyenv.git ~/.pyenv
RUN echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
RUN echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
RUN echo 'eval "$(pyenv init -)"' >> ~/.bashrc
RUN source ~/.bashrc

RUN /root/.pyenv/bin/pyenv install --list
RUN /root/.pyenv/bin/pyenv install 3.6.8 -v
RUN /root/.pyenv/bin/pyenv global 3.6.8

#設定時區
RUN echo 'Asia/Shanghai' >/etc/timezone

安裝cx-Oracle包時候注意事項,先安裝client

RUN mkdir -p /product/oracle/client

RUN cd /product/oracle/client && wget https://download.oracle.com/otn_software/linux/instantclient/195000/oracle-instantclient19.5-basic-19.5.0.0.0-1.x86_64.rpm && rpm -ivh oracle-instantclient19.5-basic-19.5.0.0.0-1.x86_64.rpm

RUN /root/.pyenv/shims/pip install cx-Oracle

命令列建立映象

  • docker build -t linux_python:3.6.8 .

使用新的映象打包服務dockerfile示例

FROM linux_python:3.6.8

RUN rm /bin/sh && ln -s /bin/bash /bin/sh
RUN mkdir -p /home/admin/blog
WORKDIR /home/admin
COPY ./ /home/admin/blog

RUN ls -la /home/admin/blog/*

RUN yum update -y && yum -y install wget curl unzip zip gcc make lsof zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel libffi-devel libpcap-devel xz-devel git make libaio libnsl

RUN /root/.pyenv/shims/pip install requests
RUN /root/.pyenv/shims/pip install django==3.0.2
RUN /root/.pyenv/shims/pip install daphne