Ver Fonte

add pytorch dockerfiles

metya há 5 anos atrás
pai
commit
9e09c47cbe
3 ficheiros alterados com 131 adições e 0 exclusões
  1. 36 0
      pytorch/Dockerfile-conda
  2. 57 0
      pytorch/Dockerfile-multistage
  3. 38 0
      pytorch/Dockerfile-pip

+ 36 - 0
pytorch/Dockerfile-conda

@@ -0,0 +1,36 @@
+FROM nvidia/cuda:10.2-base-ubuntu18.04
+
+# Install some basic utilities
+RUN apt update && apt install -y \
+    curl \
+    ca-certificates \
+    sudo \
+    git \
+    bzip2 \
+    libx11-6 \
+    && apt autoclean && apt autoremove \
+    && rm -rf /var/lib/apt/lists /var/cache/apt/archives
+
+# Create a working directory
+RUN mkdir /app
+WORKDIR /app
+
+# Create a non-root user and switch to it
+RUN adduser --disabled-password --gecos '' --shell /bin/bash user \
+    && chown -R user:user /app
+RUN echo "user ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/90-user
+USER user
+
+# All users can use /home/user as their home directory
+ENV HOME=/home/user
+RUN chmod 777 /home/user
+
+# Install Miniconda and Pytorch with Python
+#ENV CONDA_AUTO_UPDATE_CONDA=false
+ENV PATH=/home/user/miniconda/bin:$PATH
+RUN curl -sLo ~/miniconda.sh https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh \
+    && chmod +x ~/miniconda.sh \
+    && ~/miniconda.sh -b -p ~/miniconda \
+    && rm ~/miniconda.sh \
+    && conda install -y -c pytorch pytorch \
+    && conda clean -ya

+ 57 - 0
pytorch/Dockerfile-multistage

@@ -0,0 +1,57 @@
+FROM nvidia/cuda:10.2-cudnn7-devel-ubuntu18.04 AS BUILD
+
+LABEL maintainer="metya"
+
+ARG CONDA_DIR=/opt/conda
+
+# Instal basic utilities
+RUN apt update && \
+    apt install -y --no-install-recommends git wget unzip bzip2 build-essential ca-certificates && \
+    apt autoremove && \
+    apt clean && \
+    rm -rf /var/lib/apt/lists /var/cache/apt/archives
+
+# Install miniconda
+ENV PATH $CONDA_DIR/bin:$PATH
+RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O /tmp/miniconda.sh && \
+    echo 'export PATH=$CONDA_DIR/bin:$PATH' > /etc/profile.d/conda.sh && \
+    /bin/bash /tmp/miniconda.sh -b -p $CONDA_DIR && \
+    apt autoremove && \
+    apt clean && \
+    rm -rf /tmp/* && \
+    rm -rf /var/lib/apt/lists /var/cache/apt/archives
+
+RUN conda install -y pytorch -c pytorch && \
+    conda clean -ay
+
+# Runtime image
+FROM nvidia/cuda:10.2-base-ubuntu18.04
+
+ARG CONDA_DIR=/opt/conda
+ARG USERNAME=docker
+ARG USERID=1000
+
+# Instal basic utilities
+RUN apt update && \
+    apt install -y --no-install-recommends git wget unzip bzip2 sudo p7zip && \
+    apt autoremove && \
+    apt clean && \
+    rm -rf 
+
+ENV PATH $CONDA_DIR/bin:$PATH
+ENV CUDA_HOME=/usr/local/cuda
+ENV CUDA_ROOT=$CUDA_HOME
+ENV PATH=$PATH:$CUDA_ROOT/bin:$HOME/bin
+ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CUDA_ROOT/lib64
+
+RUN mkdir -p /opt/conda/
+
+# Create the user
+RUN useradd --create-home -s /bin/bash --no-user-group -u $USERID $USERNAME && \
+    chown $USERNAME $CONDA_DIR -R && \
+    adduser $USERNAME sudo && \
+    echo "$USERNAME ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
+USER $USERNAME
+WORKDIR /home/$USERNAME
+
+COPY --chown=1000 --from=build /opt/conda/. $CONDA_DIR

+ 38 - 0
pytorch/Dockerfile-pip

@@ -0,0 +1,38 @@
+FROM nvidia/cuda:10.2-base-ubuntu18.04
+
+# Install some basic utilities
+RUN apt-get update && apt-get install -y \
+    curl \
+    ca-certificates \
+    sudo \
+    git \
+    bzip2 \
+    libx11-6 \
+    python3.8 \
+    python3-pip \
+    && apt autoclean && apt autoremove \
+    && rm -rf /var/lib/apt/lists /var/cache/apt/archives
+
+RUN alias pip=pip3 python=python3.8
+
+RUN pip install --no-cache-dir torch opencv-python
+
+RUN rm -rf ~/.cache/pip/*
+
+# Create a working directory
+RUN mkdir /app
+WORKDIR /app
+
+# Create a non-root user and switch to it
+RUN adduser --disabled-password --gecos '' --shell /bin/bash user \
+    && chown -R user:user /app
+RUN echo "user ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/90-user
+USER user
+
+# All users can use /home/user as their home directory
+ENV HOME=/home/user
+RUN chmod 777 /home/user
+
+
+# Set the default command to python3
+ENTRYPOINT [ "bash" ]