Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐳 Docker #108

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pretrained_models/
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ pretrained_models
./*.png
./*.mp4
demo/tmp
demo/outputs
demo/outputs
.cache
.bash_history
56 changes: 56 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
FROM nvidia/cuda:12.3.1-devel-ubuntu20.04

ENV DEBIAN_FRONTEND=noninteractive

WORKDIR /home/models

RUN apt-get update && apt-get install -y \
python3.10 \
python3-pip \
ffmpeg \
wget \
sudo \
openssh-server \
fail2ban \
software-properties-common \
apt-transport-https \
ca-certificates \
gnupg-agent \
libgl1 \
libglib2.0-0 \
lshw \
libtcmalloc-minimal4 \
apt-utils

RUN mkdir /var/run/sshd
RUN echo 'root:root' | chpasswd
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile

RUN wget https://repo.anaconda.com/archive/Anaconda3-2023.09-0-Linux-x86_64.sh && \
bash Anaconda3-2023.09-0-Linux-x86_64.sh -b -p /anaconda && \
rm Anaconda3-2023.09-0-Linux-x86_64.sh

COPY environment.yaml /home/models/environment.yaml

ENV PATH="/home/models/.local/bin:/anaconda/bin:${PATH}"
ENV PATH="/anaconda/bin:${PATH}"
RUN echo "source /anaconda/etc/profile.d/conda.sh" >> /etc/profile
RUN /anaconda/bin/conda env create -f environment.yaml
ENV PATH="/anaconda/envs/manimate/bin:${PATH}"

RUN useradd -m -s /bin/bash models && echo "models:root" | chpasswd && adduser models sudo
RUN echo 'models ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

COPY . .

RUN chown -R models:models /home/models

EXPOSE 7860 22

CMD ["sh", "-c", "service ssh start && tail -f /dev/null"]

#ssh -L 7860:127.0.0.1:7860 -p 2222 models@localhost

38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,44 @@ python3 -m demo.gradio_animate_dist
```
Then open gradio demo in local browser.

## 🐳 Docker

Running code in environments other than Linux can be challenging. Docker is a great solution for this. Install [Docker](https://docs.docker.com/engine/install/) and [Nvidia-container-runtime](https://nvidia.github.io/nvidia-container-runtime/). Place pretrained_models as expected. Docker will ignore models in the building stage.

### Building and Running the Docker Image

Run the following command to build and start the Docker image/container::

```bash
docker-compose up -d
```

Open a terminal and create an SSH tunnel to the Docker container:

```bash
ssh -L 7860:127.0.0.1:7860 -p 2222 models@localhost
```

Password: `root`

Execute `./entrypoint.sh` to run the Gradio demo. The Gradio demo will be available at [http://localhost:7860](http://localhost:7860).

The SSH tunnel needs to remain active at all times for the Gradio demo to work. Additionally, you need to be inside the Docker container to execute commands.

Before running commands like:

```bash
python3 -m magicanimate.pipelines.animation --config configs/prompts/animation.yaml
```

or any other command that is not a script that automatically activates the environment, make sure to have the conda environment active:

```bash
conda activate manimate
```

A volume is mounted at the root directory and all changes, files, etc. will be saved in the root directory and accessible from the Docker container.

## 🙏 Acknowledgements
We would like to thank [AK(@_akhaliq)](https://twitter.com/_akhaliq?lang=en) and huggingface team for the help of setting up oneline gradio demo.

Expand Down
16 changes: 16 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: '3.8'
services:
manimate:
build: .
volumes:
- ./:/home/models
ports:
- "7860:7860"
- "2222:22" #ssh -L 7860:127.0.0.1:7860 -p 2222 models@localhost
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1
capabilities: [gpu]
11 changes: 11 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

ENV_NAME="manimate"

echo "Activating Conda environment $ENV_NAME..."
source $(conda info --base)/etc/profile.d/conda.sh
conda activate $ENV_NAME

echo "Running manimate..."
python3 -m demo.gradio_animate