Skip to content

Commit 817dce6

Browse files
committed
Switch to multi-stage build for image
Also don't download Torch models More complicated file (and will take longer on first run) but image is 16GB -> 9GB.
1 parent 13565fc commit 817dce6

File tree

2 files changed

+37
-25
lines changed

2 files changed

+37
-25
lines changed

.dockerignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
# Ignore hidden files and directories
2-
.*
2+
**/.*
33

44
# Ignore git directories (redundant)
55
.git
66
.gitattributes
77

88
# Ignore generated user results
99
results/user_inference/*
10+
11+
# Do not include PDBBind files
12+
# (quite likely they are in the same directory)
13+
**/pdbbind_sequences.fasta
14+
**/PDBBind_processed/

docker/cuda-ubuntu22.04/Dockerfile

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,54 @@
1-
FROM nvidia/cuda:11.7.1-devel-ubuntu22.04
1+
# Stage 1: Build Environment Setup
2+
FROM nvidia/cuda:11.7.1-devel-ubuntu22.04 as builder
23

3-
RUN apt-get update -y
4-
RUN apt-get install -y sudo wget curl nano git && rm -rf /var/lib/apt/lists/*
4+
RUN apt-get update -y && apt-get install -y wget curl git tar bzip2 && rm -rf /var/lib/apt/lists/*
55

66
# Create a user
77
ENV APPUSER="appuser"
88
ENV HOME=/home/$APPUSER
99
RUN useradd -m -u 1000 $APPUSER
10-
1110
USER $APPUSER
1211
WORKDIR $HOME
1312

14-
RUN mkdir -p ~/.cache/torch/hub/checkpoints
15-
# Download ESM models
16-
ENV ESM_MODEL="esm2_t33_650M_UR50D"
17-
ENV CONTACT_MODEL="$ESM_MODEL-contact-regression"
18-
RUN curl -o ~/.cache/torch/hub/checkpoints/$ESM_MODEL.pt https://dl.fbaipublicfiles.com/fair-esm/models/$ESM_MODEL.pt
19-
RUN curl -o ~/.cache/torch/hub/checkpoints/$CONTACT_MODEL.pt https://dl.fbaipublicfiles.com/fair-esm/regression/$CONTACT_MODEL.pt
13+
ENV ENV_NAME="diffdock-pocket"
2014

21-
# Build is significantly faster with micromamba, rather than conda
15+
# Install micromamba
2216
RUN curl -Ls https://micro.mamba.pm/api/micromamba/linux-64/latest | tar -xj bin/micromamba
23-
24-
# Set the environment variables
25-
ENV MAMBA_ROOT_PREFIX=$HOME/micromamba
2617
ENV PATH=$HOME/bin:$HOME/.local/bin:$PATH
2718

28-
RUN ~/bin/micromamba shell init -s bash --root-prefix $MAMBA_ROOT_PREFIX # this writes to your .bashrc file
29-
RUN ~/bin/micromamba --version
30-
31-
# Create conda environment first
32-
# This is time-consuming and don't want to reproduce it often
19+
# Copy and create Conda environment
3320
ENV ENV_FILE_NAME=environment.yml
34-
ENV ENV_NAME="diffdock-pocket"
3521
COPY --chown=$APPUSER:$APPUSER ./$ENV_FILE_NAME .
22+
RUN ~/bin/micromamba env create --file $ENV_FILE_NAME && ~/bin/micromamba clean -afy --quiet
3623

37-
RUN ~/bin/micromamba env create --file $ENV_FILE_NAME && ~/bin/micromamba clean -afy
38-
24+
# Copy application code
3925
COPY --chown=$APPUSER:$APPUSER . $HOME/DiffDock-Pocket
4026

27+
# Stage 2: Runtime Environment
28+
FROM nvidia/cuda:11.7.1-runtime-ubuntu22.04
29+
30+
# Create user and setup environment
31+
ENV APPUSER="appuser"
32+
ENV HOME=/home/$APPUSER
33+
RUN useradd -m -u 1000 $APPUSER
34+
USER $APPUSER
35+
WORKDIR $HOME
36+
37+
ENV ENV_NAME="diffdock-pocket"
38+
39+
# Copy the Conda environment and application code from the builder stage
40+
COPY --from=builder --chown=$APPUSER:$APPUSER $HOME/micromamba $HOME/micromamba
41+
COPY --from=builder --chown=$APPUSER:$APPUSER $HOME/bin $HOME/bin
42+
COPY --from=builder --chown=$APPUSER:$APPUSER $HOME/DiffDock-Pocket $HOME/DiffDock-Pocket
4143
WORKDIR $HOME/DiffDock-Pocket
4244

43-
# Expose default streamlit and gradio ports
45+
# Set the environment variables
46+
ENV MAMBA_ROOT_PREFIX=$HOME/micromamba
47+
ENV PATH=$HOME/bin:$HOME/.local/bin:$PATH
48+
RUN micromamba shell init -s bash --root-prefix $MAMBA_ROOT_PREFIX
49+
50+
# Expose ports for streamlit and gradio
4451
EXPOSE 7860 8501
4552

46-
# Default command just prints the device (CPU or GPU), also ensure using correct python
53+
# Default command
4754
CMD ["sh", "-c", "micromamba run -n ${ENV_NAME} python utils/print_device.py"]

0 commit comments

Comments
 (0)