1、Dockerfile文件
参考资料:Docker 构建自定义镜像和Dockerfile文件
2、CentOS7 安装 Python 2.7.5 和 PIP的Dockerfile文件
Dockerfile文件内容如下:
ARG CENTOS_VERSION=7 FROM centos:$CENTOS_VERSION # Python 2.7.5 is installed with centos7 image # Add repository for PIP RUN yum install -y epel-release # Install pip RUN yum install -y python-pip RUN python --version ENTRYPOINT [ "python" ]
3、Ubuntu 安装 Python 2.7.5 的 Dockerfile文件
Dockerfile文件内容如下:
ARG UBUNTU_VERSION=18.04 FROM ubuntu:$UBUNTU_VERSION ARG PYTHON_VERSION=2.7.5 # Install dependencies # PIP - openssl version > 1.1 may be an issue (try older ubuntu images) RUN apt-get update \ && apt-get install -y wget gcc make openssl libffi-dev libgdbm-dev libsqlite3-dev libssl-dev zlib1g-dev \ && apt-get clean WORKDIR /tmp/ # Build Python from source RUN wget https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tgz \ && tar --extract -f Python-$PYTHON_VERSION.tgz \ && cd ./Python-$PYTHON_VERSION/ \ && ./configure --enable-optimizations --prefix=/usr/local \ && make && make install \ && cd ../ \ && rm -r ./Python-$PYTHON_VERSION* RUN python --version ENTRYPOINT [ "python" ]
或者
ARG UBUNTU_VERSION=16.04 FROM ubuntu:$UBUNTU_VERSION # Install dependencies RUN apt-get update \ && apt-get install -y wget gcc make openssl libffi-dev libgdbm-dev libsqlite3-dev libssl-dev zlib1g-dev \ && apt-get clean WORKDIR /tmp/ # Build python from source RUN wget https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tgz \ && tar --extract -f Python-$PYTHON_VERSION.tgz \ && cd ./Python-$PYTHON_VERSION/ \ && ./configure --enable-optimizations --prefix=/usr/local \ && make && make install \ && cd ../ \ && rm -r ./Python-$PYTHON_VERSION* # Build pip from source RUN wget https://bootstrap.pypa.io/pip/2.7/get-pip.py \ && python get-pip.py RUN python --version ENTRYPOINT [ "python" ]
4、Ubuntu 安装 Python 2.7.6 和 PIP 的 Dockerfile文件
Dockerfile文件内容如下:
ARG UBUNTU_VERSION=14.04 FROM ubuntu:$UBUNTU_VERSION RUN apt-get update \ && apt-get install -y python python-pip \ && apt-get clean RUN python --version ENTRYPOINT [ "python" ]
5、Ubuntu 安装 Python 2.7.9 和 PIP 的 Dockerfile文件
Dockerfile文件内容如下:
ARG UBUNTU_VERSION=16.04 FROM ubuntu:$UBUNTU_VERSION ARG PYTHON_VERSION=2.7.9 # Install dependencies RUN apt-get update \ && apt-get install -y wget gcc make openssl libffi-dev libgdbm-dev libsqlite3-dev libssl-dev zlib1g-dev \ && apt-get clean WORKDIR /tmp/ # Build Python from source RUN wget https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tgz \ && tar --extract -f Python-$PYTHON_VERSION.tgz \ && cd ./Python-$PYTHON_VERSION/ \ && ./configure --with-ensurepip=install --enable-optimizations --prefix=/usr/local \ && make && make install \ && cd ../ \ && rm -r ./Python-$PYTHON_VERSION* RUN python --version \ && pip --version ENTRYPOINT [ "python" ]