Skip to content

Commit

Permalink
edit dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
HRashidi committed Aug 15, 2024
1 parent 899ddc5 commit f222358
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
7 changes: 3 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Use NVIDIA CUDA as base image
FROM nvidia/cuda:12.4.1-devel-ubuntu22.04
FROM nvidia/cuda:12.1.1-cudnn8-devel-ubuntu22.04

# Set working directory
WORKDIR /app
Expand All @@ -8,8 +8,7 @@ WORKDIR /app
ENV DEBIAN_FRONTEND=non-interactive

# Install required libraries, tools, and Python3
RUN apt-get update && apt-get install -y libgl1 libglib2.0-0 ffmpeg curl git python3.10 python3-pip nvidia-cuda-toolkit
ENV LD_LIBRARY_PATH=/usr/local/cuda/compat:$LD_LIBRARY_PATH
RUN apt-get update && apt-get install -y ffmpeg curl git python3.10 python3-pip

# Install poetry
RUN curl -sSL https://install.python-poetry.org | python3 -
Expand All @@ -25,7 +24,7 @@ COPY . /app
RUN poetry install

# Install flash attention
RUN poetry run pip install torch torchvision --index-url https://download.pytorch.org/whl/cu124
RUN poetry run pip install torch --index-url https://download.pytorch.org/whl/cu121
RUN poetry run pip install flash-attn --no-build-isolation

# Disable buffering for stdout and stderr to get the logs in real time
Expand Down
20 changes: 13 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,20 @@ For example, if your application has `/summary` endpoint that accepts videos, yo
curl -X POST http://127.0.0.1:8000/summary -Fbody='{"video":{"url":"https://www.youtube.com/watch?v=VhJFyyukAzA"}}'
```

## Running inside the Docker
## Running within Docker

To run the project via docker, a dockerfile and docker-compose config are available in the repo. you can run it via docker-compose or directly via docker as follows:
To run the project using Docker, you will find both a Dockerfile and a Docker Compose configuration file in the repository. These resources allow you to run the project seamlessly. You have the option to launch it using Docker Compose for a more streamlined approach, or you can opt to use Docker directly. Here’s how you can do both:

### Deploying via docker-compose

```bash
CUDA_VISIBLE_DEVICES=0 docker-compose up
```
If your application needs GPU to run, you need to specify `CUDA_VISIBLE_DEVICES` in the command.
The docker-compose config, would deploy a Postgres instance besides the application and link them to each other. If you already have a database somewhere you can edit the docker-compose config, remove the Postgres and set the Postgres address via the environment variables.
The app would be available at `http://localhost:8000` in the host server and the Postgres would be accessible via port 15430.
You can check the [Docker Compose Config](./docker-compose.yaml) to see all available variables you can set for running the application.

When your application requires a Graphics Processing Unit (GPU) to run, it's essential to specify the index of the GPU you want to use. This is crucial because most systems have multiple GPUs, and you need to instruct the system which one to utilize. To achieve this, you can use the `CUDA_VISIBLE_DEVICES` environment variable.

The docker-compose configuration will deploy a PostgreSQL instance alongside the application and establish a connection between them. If you already have a database set up elsewhere, you can modify the docker-compose configuration by removing PostgreSQL and specifying the PostgreSQL address using environment variables. The application will be accessible at `http://localhost:8000` in the host server and the PostgreSQL will be accessible via port 15430.
You can check the [docker-compose config](./docker-compose.yaml) to see all available variables you can set for running the application.

### Deploying via docker

Expand All @@ -140,5 +141,10 @@ docker build --no-cache -t aana_app_project:latest .

2. Run the the image:
```bash
docker run --rm -it -v ~/.cache:/root/.cache -e CUDA_VISIBLE_DEVICES="0,1" -e DB_CONFIG=$DB_CONFIG -p 8000:8000 aana_app_project:latest
export DB_CONFIG='{"datastore_type":"postgresql","datastore_config":{"host":<PG_HOST>,"port":<PG_PORT>,"user":<PGUSER>,"password":<PG_PASSWORD>,"database":<PG_DB>}}'
docker run --rm -it -v ~/.cache:/root/.cache -e CUDA_VISIBLE_DEVICES=0 -e DB_CONFIG=$DB_CONFIG -p 8000:8000 aana_app_project:latest
```

The Dockerfile is currently configured to utilize the base image `nvidia/cuda:12.1.1-cudnn8-devel-ubuntu22.04`. This particular image integrates CUDA and cuDNN, making it well-suited for applications that require GPU acceleration and deep learning functionalities. However, if you're planning to deploy the container on a server where the installed NVIDIA driver is incompatible with this specific image, you may need to modify the base image. It's essential to choose a version that aligns with the capabilities of the existing driver on your server to ensure optimal performance and functionality. Always verify the compatibility of the CUDA version with your server’s GPU driver to avoid any issues during deployment.

To ensure that your application runs correctly in the Docker container, you need to specify the third-party libraries you want to use in the Dockerfile. This involves installing the necessary libraries using the RUN command, which executes a command in the container and commits the results.
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ services:
TMP_DATA_DIR: /tmp/aana_data
DB_CONFIG: '{"datastore_type":"postgresql","datastore_config":{"host":"postgres","port":"15430","user":"${POSTGRES_USER:-aana_db_user}","password":"${POSTGRES_PASSWORD:-Yf?5nX39}","database":"${POSTGRES_DB:-aana_db}"}}'
volumes:
- app_data:/tmp/aana
- app_data:/tmp/aana_data
- hf_datasets_cache:/root/.cache/huggingface

volumes:
Expand Down

0 comments on commit f222358

Please sign in to comment.