使用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

posted @ 2020-07-22 22:21  今日店休  阅读(2650)  评论(0编辑  收藏  举报