Skip to content

Instantly share code, notes, and snippets.

@dvsseed
Created June 21, 2022 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dvsseed/4ee0e6b2a3cbcf78764d2f0cf9cc5968 to your computer and use it in GitHub Desktop.
Save dvsseed/4ee0e6b2a3cbcf78764d2f0cf9cc5968 to your computer and use it in GitHub Desktop.
Create a docker file for Ubuntu 20.04, CUDA 10.2, MiniConda, Python 3.10, PyTorch 1.11.0
# Define base image
# FROM nvidia/cuda:11.3.0-runtime-ubuntu20.04
# FROM nvidia/cuda:11.3.0-cudnn8-runtime-ubuntu20.04
# FROM nvidia/cuda:11.3.0-cudnn8-devel-ubuntu20.04
FROM nvidia/cuda:11.0.3-cudnn8-devel-ubuntu20.04
ENV PATH="/root/miniconda3/bin:${PATH}"
ARG PATH="/root/miniconda3/bin:${PATH}"
RUN sed -i 's/http:\/\/archive.ubuntu.com\/ubuntu/http:\/\/free.nchc.org.tw\/ubuntu/g' /etc/apt/sources.list
# tzdata need to be install first
# https://stackoverflow.com/questions/44331836/apt-get-install-tzdata-noninteractive
RUN ln -fs /usr/share/zoneinfo/Asia/Taipei /etc/localtime \
&& apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata \
&& dpkg-reconfigure --frontend noninteractive tzdata \
&& rm -rf /var/lib/apt/lists/*
# OpenCV needs ffmpeg libsm6 libxext6
# https://stackoverflow.com/questions/55313610/importerror-libgl-so-1-cannot-open-shared-object-file-no-such-file-or-directo
RUN apt-get update \
&& apt-get install -y build-essential git wget curl bzip2 unzip g++ binutils locales nano checkinstall zlib1g-dev libssl-dev \
&& apt-get install -y libjpeg-dev libpng-dev iputils-ping net-tools libgl1 libglib2.0-0 \
&& apt-get install -y python3-pip git python-is-python3 ffmpeg libsm6 libxext6 \
&& rm -rf /var/lib/apt/lists/*
# Install CMake lastest by Compiling Source
RUN wget https://github.com/Kitware/CMake/releases/download/v3.21.7/cmake-3.21.7.tar.gz \
&& tar -zxvf cmake-3.21.7.tar.gz \
&& cd cmake-3.21.7 \
&& ./bootstrap \
&& make \
&& make install \
&& cp bin/cmake /usr/bin/ \
&& cd .. \
&& rm -f cmake-3.21.7.tar.gz \
&& rm -rf cmake-3.21.7
# Latest Miniconda Installer Links
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh \
&& mkdir /root/.conda \
&& bash Miniconda3-latest-Linux-x86_64.sh -b \
&& rm -f Miniconda3-latest-Linux-x86_64.sh
# RUN conda --version
# Update conda
RUN conda update -n base -c defaults conda
# Set working directory for the project
WORKDIR /tadnn
# Create env tadnn with python 3.10
# RUN conda create -n tadnn pytorch torchvision torchaudio cudatoolkit=11.3 --yes -c pytorch
RUN conda create -n tadnn pytorch torchvision torchaudio cudatoolkit=10.2 --yes -c pytorch
# Init conda
RUN conda init bash
# Switch to tadnn env then install ffmpeg
SHELL ["conda", "run", "-n", "tadnn", "/bin/bash", "-c"]
RUN conda install -y tqdm matplotlib pandas psutil -c conda-forge
RUN conda clean -ya \
&& conda clean -y --force-pkgs-dirs
RUN pip install opencv-python torchsummary
# RUN pip install opencv-python torchsummary torchlars
# COPY requirements.txt .
# RUN conda install -y --file requirements.txt
# Create Conda environment from the YAML file
# COPY environment.yml .
# RUN conda env create -f environment.yml
# Initialize conda in bash config fiiles:
# RUN conda init bash
# SHELL ["/bin/bash", "--login", "-c"]
# RUN source ~/.bashrc
# RUN cd /tadnn/build \
# && ./conda_build.sh
# Make RUN commands use the new environment:
RUN echo "export CUDA_HOME=/usr/local/cuda" >> ~/.bashrc
RUN echo "export PATH=$PATH:$CUDA_HOME/bin" >> ~/.bashrc
RUN echo "export LD_LIBRARY_PATH=/usr/local/cuda-11.3/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}" >> ~/.bashrc
RUN echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-11.3/extras/CUPTI/lib64" >> ~/.bashrc
RUN echo "conda activate tadnn" >> ~/.bashrc
# Activate the environment, and make sure it's activated:
# RUN conda activate tadnn
# RUN echo "Make sure tadnn is installed:"
# RUN python -c "import torch; print(torch.__version__); print(torch.cuda.is_available());"
# Override default shell and use bash
# SHELL ["conda", "run", "-n", "tadnn", "/bin/bash", "-c"]
# Activate Conda environment and check if it is working properly
# RUN echo "Making sure tadnn is installed correctly..."
# RUN python -c "import torch; print(torch.__version__); print(torch.cuda.is_available());"
# Python program to run in the container
# COPY run.py .
# ENTRYPOINT ["conda", "run", "-n", "env", "python", "run.py"]
# PyTorch
# RUN python3 -m pip --no-cache-dir install torch torchvision --extra-index-url https://download.pytorch.org/whl/cu113
# RUN conda install -y pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch
# Build Project
# RUN bash ./conda_build.sh
# RUN cd ../pytorch
# WORKDIR /tadnn/pytorch
# The code to run when container is started:
# COPY entrypoint.sh .
# ENTRYPOINT ["./entrypoint.sh"]
# ENTRYPOINT ["python", "experi_stl10_resnet9_mslbphist2_bgc_pooling_train.py"]
# ENTRYPOINT ["conda", "run", "-n", "tadnn", "python", "experi_stl10_resnet9_mslbphist2_bgc_pooling_train.py"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment