Dockerfile模板

下面是比较欣赏的Dockerfile模板.

Dockerfile模板

  1. 层次比较清晰
  2. 如果一次构建失败, 可以重复构建
  3. 不同镜像可以复用构建过程的层

FROM nvidia/cuda:9.0-cudnn7-devel-ubuntu16.04

RUN APT_INSTALL="apt-get install -y --no-install-recommends" && \
    PIP_INSTALL="python -m pip --no-cache-dir install --upgrade" && \
    GIT_CLONE="git clone --depth 10" && \

    rm -rf /var/lib/apt/lists/* \
           /etc/apt/sources.list.d/cuda.list \
           /etc/apt/sources.list.d/nvidia-ml.list && \

    apt-get update 

# ==================================================================
# tools
# ------------------------------------------------------------------

RUN    APT_INSTALL="apt-get install -y --no-install-recommends" && \
DEBIAN_FRONTEND=noninteractive $APT_INSTALL \
        build-essential \
        ca-certificates \
        cmake \
        wget \
        git \
        vim \      
         imagemagick \
         libopencv-dev \
         python-opencv \
         curl \
         libjpeg-dev \
         libpng-dev \
         axel \
         zip \
         unzip 


# ==================================================================
# python
# ------------------------------------------------------------------

RUN  APT_INSTALL="apt-get install -y --no-install-recommends" && \  
DEBIAN_FRONTEND=noninteractive $APT_INSTALL \
        software-properties-common \
        && \
    add-apt-repository ppa:deadsnakes/ppa && \
    apt-get update && \
    DEBIAN_FRONTEND=noninteractive $APT_INSTALL \
        python3.6 \
        python3.6-dev \
        && \
    wget -O ~/get-pip.py \
        https://bootstrap.pypa.io/get-pip.py && \
    python3.6 ~/get-pip.py && \
    ln -s /usr/bin/python3.6 /usr/local/bin/python3 && \
    ln -s /usr/bin/python3.6 /usr/local/bin/python && \
    $PIP_INSTALL \
        setuptools \
        && \
    $PIP_INSTALL \
        numpy \
        scipy \
        pandas \
        scikit-learn \
        matplotlib \
        Cython 

# ==================================================================
# pytorch
# ------------------------------------------------------------------

RUN PIP_INSTALL="python -m pip --no-cache-dir install --upgrade" && \   
$PIP_INSTALL \
        http://download.pytorch.org/whl/cu90/torch-0.4.0-cp36-cp36m-linux_x86_64.whl \
        torchvision \
        && \
    $PIP_INSTALL \
        cupy-cuda90 \
       pynvrtc  && \


# ==================================================================
# config & cleanup
# ------------------------------------------------------------------

    ldconfig && \
    apt-get clean && \
    apt-get autoremove && \
    rm -rf /var/lib/apt/lists/* /tmp/* ~/*

下面三行清理空间

apt-get clean && \
apt-get autoremove && \
rm -rf /var/lib/apt/lists/* /tmp/* ~/*

你可能感兴趣的:(docker)