-
Notifications
You must be signed in to change notification settings - Fork 0
/
dlwpt.dockerfile
83 lines (69 loc) · 3.53 KB
/
dlwpt.dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Start from an Ubuntu 20.04 base image
FROM ubuntu:20.04
WORKDIR ~
# Avoid prompts from apt during installation
ENV DEBIAN_FRONTEND=noninteractive
# Set up Conda environment variables
ENV CONDA_DIR /opt/conda
ENV PATH $CONDA_DIR/bin:$PATH
# Install necessary packages, Miniconda, tmux, SSH, and set up Conda environment in one layer
RUN apt-get update && apt-get install -y \
wget bzip2 ca-certificates git curl gnupg lsb-release libarchive13 tmux openssh-server \
&& wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh \
&& /bin/bash ~/miniconda.sh -b -p $CONDA_DIR \
&& rm ~/miniconda.sh \
&& conda init bash \
&& conda update -n base -c defaults conda \
&& conda install -n base -c conda-forge conda-libmamba-solver \
&& conda config --set solver libmamba \
&& conda create -n pytorch_env python=3.10 \
&& conda clean -afy \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* $CONDA_DIR/pkgs /root/.conda/cache/*
# Set up NVIDIA container toolkit
RUN curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \
&& curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \
sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list \
&& apt-get update \
&& apt-get install -y nvidia-container-toolkit \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Set shell to use conda environment by default
SHELL ["conda", "run", "-n", "pytorch_env", "/bin/bash", "-c"]
# Install common packages
RUN conda install -y \
numpy pandas matplotlib plotly jupyter jupyterlab seaborn scipy sympy \
&& conda install -y -c conda-forge ipyvolume diskcache \
&& conda install -y -c simpleitk simpleitk
# Install both GPU and CPU PyTorch versions
RUN conda install -y -c pytorch -c nvidia \
pytorch torchvision torchaudio pytorch-cuda=12.1 \
&& conda install -y -c pytorch \
pytorch torchvision torchaudio cpuonly
# Final updates and cleanup
RUN conda update --all \
&& conda clean -afy \
&& rm -rf $CONDA_DIR/pkgs /root/.conda/cache/*
# Install VSCode
RUN apt-get update \
&& apt-get install -y wget gpg apt-transport-https \
&& wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg \
&& install -o root -g root -m 644 microsoft.gpg /etc/apt/trusted.gpg.d/ \
&& echo "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list \
&& apt-get update \
&& apt-get install -y code \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* microsoft.gpg
# Set up SSH
RUN mkdir /var/run/sshd \
&& echo 'root:root' | chpasswd \
&& sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config \
&& sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config
# Expose SSH and Jupyter ports
EXPOSE 22 8888
# Create a script to run VSCode with necessary arguments
RUN echo '#!/bin/bash\ncode --no-sandbox --user-data-dir=/root/.vscode-root "$@"' > /usr/local/bin/code-root \
&& chmod +x /usr/local/bin/code-root
# Start SSH service and keep the container running
CMD service ssh start && tail -f /dev/null