美文网首页
dockerfile

dockerfile

作者: Plenari | 来源:发表于2019-11-14 22:15 被阅读0次
  • 用来构建包含深度学习库的镜像,并且尽可能包含较多的python包使用方法:

    • 新建文件夹scipy
    • 新建三个文件
      • req.txt 内容
      • sources.conf 内容
      • dockerFile 内容如下:
    • 在scipy里执行命令:
      docker build -f dockerFile -t python:scipy .
  • dockerFile 内容

FROM ubuntu:18.04

ENV TENSORFLOW_VERSION=2.0.0
ENV PYTORCH_VERSION=1.3.0
ENV TORCHVISION_VERSION=0.4.1
ENV MXNET_VERSION=1.5.0

# Python 2.7 or 3.6 is supported by Ubuntu Bionic out of the box
ARG python=3.6
ENV PYTHON_VERSION=${python}

# Set default shell to /bin/bash
SHELL ["/bin/bash", "-cu"]
# download sources.list to current dir
ADD ./sources.list /etc/apt/sources.list
RUN apt-get update && apt-get install -y --allow-downgrades --allow-change-held-packages --no-install-recommends \
        build-essential \
        cmake \
        g++-4.8 \
        git \
        curl \
        vim \
        wget \
        ca-certificates \
        libjpeg-dev \
        libpng-dev \
        python${PYTHON_VERSION} \
        python${PYTHON_VERSION}-dev \
        librdmacm1 \
        libibverbs1 \
        ibverbs-providers \
        libglib2.0-0 \ 
        libsm6 \
        libxrender-dev \
        libxext6 

RUN if [[ "${PYTHON_VERSION}" == "3.6" ]]; then \
        apt-get install -y python${PYTHON_VERSION}-distutils; \
    fi
RUN ln -s /usr/bin/python${PYTHON_VERSION} /usr/bin/python
# 如果实在下载不下来pip,可以手动下载,然后指定本地文件安装
#ADD ./pip-19.3.1-py2.py3-none-any.whl /home/pip-19.3.1-py2.py3-none-any.whl
#RUN python get-pip.py pip==19.3.1 --find-links=/home/pip-19.3.1-py2.py3-none-any.whl 
RUN curl -O https://bootstrap.pypa.io/get-pip.py && \
    python get-pip.py && \
    rm get-pip.py
# set pip
RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pip -U
RUN pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple 
# Install TensorFlow, Keras, PyTorch and MXNet
RUN pip install future typing
RUN pip install numpy \
        tensorflow==${TENSORFLOW_VERSION} \
        keras \
        h5py
RUN pip install torch==${PYTORCH_VERSION} torchvision==${TORCHVISION_VERSION}
RUN pip install mxnet==${MXNET_VERSION}
# 换成aliyun
RUN pip config set global.index-url http://mirrors.aliyun.com/pypi/simple/
ADD ./req.txt /etc/apt/req.txt
RUN pip install -r /etc/apt/req.txt --trusted-host mirrors.aliyun.com

# Install Open MPI
RUN mkdir /tmp/openmpi && \
    cd /tmp/openmpi && \
    wget https://www.open-mpi.org/software/ompi/v4.0/downloads/openmpi-4.0.0.tar.gz && \
    tar zxf openmpi-4.0.0.tar.gz && \
    cd openmpi-4.0.0 && \
    ./configure --enable-orterun-prefix-by-default && \
    make -j $(nproc) all && \
    make install && \
    ldconfig && \
    rm -rf /tmp/openmpi

# Install OpenSSH for MPI to communicate between containers
RUN apt-get install -y --no-install-recommends openssh-client openssh-server && \
    mkdir -p /var/run/sshd

# Allow OpenSSH to talk to containers without asking for confirmation
RUN cat /etc/ssh/ssh_config | grep -v StrictHostKeyChecking > /etc/ssh/ssh_config.new && \
    echo "    StrictHostKeyChecking no" >> /etc/ssh/ssh_config.new && \
    mv /etc/ssh/ssh_config.new /etc/ssh/ssh_config
# 清华下载太多了,不让下
RUN pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple 
#WORKDIR "/examples"

相关文章

网友评论

      本文标题:dockerfile

      本文链接:https://www.haomeiwen.com/subject/lqddictx.html