|
| 1 | +FROM pytorch/pytorch:2.4.1-cuda12.4-cudnn9-runtime |
| 2 | + |
| 3 | +ARG USERNAME=fmpose3d |
| 4 | +ARG USER_UID=1000 |
| 5 | +ARG USER_GID=1000 |
| 6 | +RUN groupadd ${USERNAME} --gid ${USER_GID} |
| 7 | +RUN useradd -m -s /bin/bash -g ${USERNAME} -u ${USER_UID} ${USERNAME} |
| 8 | +RUN mkdir /app /logs /data |
| 9 | + |
| 10 | +ENV DEBIAN_FRONTEND=noninteractive |
| 11 | +SHELL ["/bin/bash", "-c"] |
| 12 | +RUN apt-get update -y && apt-get install -yy --no-install-recommends \ |
| 13 | + vim zsh tmux wget curl htop git sudo ssh git-lfs \ |
| 14 | + python3 python3-pip \ |
| 15 | + libgl1-mesa-glx libglib2.0-0 \ |
| 16 | + ffmpeg \ |
| 17 | + && apt-get -y autoclean \ |
| 18 | + && apt-get -y autoremove \ |
| 19 | + && rm -rf /var/lib/apt/lists/* \ |
| 20 | + && apt-get clean |
| 21 | + |
| 22 | +ENV PATH="/opt/conda/bin:${PATH}" |
| 23 | + |
| 24 | +# Initialize conda for root just in case and fix symlinks |
| 25 | +RUN ln -fs /opt/conda/etc/profile.d/conda.sh /etc/profile.d/conda.sh |
| 26 | + |
| 27 | +# --- Install FMPose3D from GitHub --- |
| 28 | +RUN python -m pip install --no-cache-dir --upgrade pip && \ |
| 29 | + git clone --depth 1 https://github.com/AdaptiveMotorControlLab/FMPose3D.git /tmp/fmpose3d && \ |
| 30 | + python -m pip install --no-cache-dir "/tmp/fmpose3d[animals,viz]" gdown && \ |
| 31 | + rm -rf /tmp/fmpose3d |
| 32 | + |
| 33 | +# Allow non-root user to download DLC model weights at runtime |
| 34 | +RUN DLC_MODELZOO_DIR="$(python -c "import site, pathlib; print(pathlib.Path(site.getsitepackages()[0]) / 'deeplabcut' / 'modelzoo')")" \ |
| 35 | + && mkdir -p "${DLC_MODELZOO_DIR}/checkpoints" \ |
| 36 | + && chown -R "${USERNAME}:${USERNAME}" "${DLC_MODELZOO_DIR}" |
| 37 | + |
| 38 | +# Set your user as owner of the home directory before switching |
| 39 | +RUN chown -R ${USERNAME}:${USERNAME} /home/${USERNAME} |
| 40 | + |
| 41 | +ENV NVIDIA_DRIVER_CAPABILITIES=all |
| 42 | + |
| 43 | +# --- SWITCH TO USER --- |
| 44 | +USER ${USERNAME} |
| 45 | +ENV HOME=/home/${USERNAME} |
| 46 | +WORKDIR ${HOME} |
| 47 | + |
| 48 | +# Ensure dotfiles exist |
| 49 | +RUN touch ${HOME}/.bashrc ${HOME}/.zshrc && \ |
| 50 | + chmod 644 ${HOME}/.bashrc ${HOME}/.zshrc |
| 51 | + |
| 52 | +# Install Oh My Zsh and plugins (MUST come before conda init, since OMZ overwrites .zshrc) |
| 53 | +RUN sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" --unattended \ |
| 54 | + && git clone https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions \ |
| 55 | + && git clone https://github.com/zsh-users/zsh-syntax-highlighting ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting \ |
| 56 | + && sed -i 's/^plugins=(.*)$/plugins=(git zsh-autosuggestions zsh-syntax-highlighting)/' ~/.zshrc \ |
| 57 | + && echo "export PATH=\$PATH:${HOME}/.local/bin" >> ~/.zshrc |
| 58 | + |
| 59 | +# Initialize conda AFTER Oh My Zsh (so conda init block is not overwritten) |
| 60 | +RUN /opt/conda/bin/conda init bash && /opt/conda/bin/conda init zsh |
| 61 | + |
| 62 | +# Add conda activation to bashrc and zshrc |
| 63 | +RUN echo "conda activate base" >> ${HOME}/.bashrc && \ |
| 64 | + echo "conda activate base" >> ${HOME}/.zshrc |
| 65 | + |
| 66 | +SHELL ["/bin/zsh", "-c"] |
| 67 | +CMD ["zsh"] |
0 commit comments