Skip to content

Instantly share code, notes, and snippets.

@ZachL1
Created May 29, 2024 09:00
Show Gist options
  • Select an option

  • Save ZachL1/380b37de47e98f3f41ce6224e2ba0c5d to your computer and use it in GitHub Desktop.

Select an option

Save ZachL1/380b37de47e98f3f41ce6224e2ba0c5d to your computer and use it in GitHub Desktop.
A simple Dockerfile to create the most basic containers containing cuda, conda and torch.
# docker build -t zach/cuda_conda:cu118-torch21 . --network host
# sudo docker run --gpus all -it --ipc=host --ulimit memlock=-1 --ulimit stack=67108864 --user root -v /mnt/:/mnt/ -v ~/workspace/:~/workspace/ --network host zach/cuda_conda:cu118-torch21
FROM nvidia/cuda:11.8.0-cudnn8-devel-ubuntu22.04
# Add some dependencies
RUN sed -i 's#http://archive.ubuntu.com/#http://mirrors.tuna.tsinghua.edu.cn/#' /etc/apt/sources.list
RUN apt-get update && \
apt-get -y install curl unzip wget git tmux htop vim net-tools cmake
# Install Miniconda
RUN wget -c https://repo.anaconda.com/miniconda/Miniconda3-py310_24.1.2-0-Linux-x86_64.sh -O Miniconda.sh && \
sh Miniconda.sh -b -p /opt/miniconda3 && \
rm Miniconda.sh
# tells docker to use bash as shell and the -c tells bash to run the following command
SHELL ["/bin/bash", "-c"]
# pip and conda config
RUN source /opt/miniconda3/bin/activate && \
pip install torch==2.1.0 torchvision==0.16.0 torchaudio==2.1.0 -i https://download.pytorch.org/whl/cu118 && \
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple && \
conda config --set show_channel_urls yes && \
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main && \
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r && \
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
RUN /bin/bash && \
source /opt/miniconda3/bin/activate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment