Skip to content

Commit 75ad204

Browse files
add nvidia Docker setup (#115)
Co-authored-by: Johannes Andersen <[email protected]>
1 parent cee8568 commit 75ad204

File tree

3 files changed

+71
-3
lines changed

3 files changed

+71
-3
lines changed

Dockerfile.gpu

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM nvidia/cuda:12.0.1-base-ubuntu22.04
2+
3+
ENV PYTHON_VERSION=3.10
4+
5+
WORKDIR /workspace
6+
7+
RUN export DEBIAN_FRONTEND=noninteractive \
8+
&& apt-get -qq update \
9+
&& apt-get -qq install --no-install-recommends \
10+
git \
11+
ffmpeg \
12+
python${PYTHON_VERSION} \
13+
python${PYTHON_VERSION}-venv \
14+
python3-pip \
15+
&& rm -rf /var/lib/apt/lists/*
16+
17+
COPY requirements.txt requirements.txt
18+
RUN pip3 install -r requirements.txt
19+
20+
COPY src src
21+
22+
CMD [ "flask", "--app" , "src/main", "--debug", "run","--host", "0.0.0.0","--port", "3000"]

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,39 @@ This will start three docker containers.
151151
- api running flask fra src
152152
- worker running rq from src
153153

154+
### Using NVIDIA CUDA with docker-compose
155+
156+
If you have a NVIDIA GPU and want to use it with docker-compose,
157+
you need to install [nvidia-docker](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#docker).
158+
159+
To enable CUDA support, you need to edit the `docker-compose.yml` file to use the `nvidia` runtime:
160+
161+
```yaml
162+
build:
163+
context: .
164+
# use Dockerfile.gpu when using a NVIDIA GPU
165+
dockerfile: Dockerfile.gpu
166+
```
167+
168+
You also have to uncomment the device reservation in the `docker-compose.yml` file:
169+
170+
```yaml
171+
deploy:
172+
resources:
173+
reservations:
174+
devices:
175+
- driver: nvidia
176+
capabilities: [gpu]
177+
```
178+
179+
Then run the following command as usual:
180+
181+
```sh
182+
docker-compose --env-file .envrc up
183+
```
184+
185+
The worker will now use the GPU acceleration.
186+
154187
### Running full setup using devcontainers
155188

156189
Install remote-development extensions (containers)

docker-compose.yaml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
version: "3.9"
22
services:
33
api:
4-
build: .
4+
build:
5+
context: .
6+
# use Dockerfile.gpu when using a NVIDIA GPU
7+
dockerfile: Dockerfile
58
ports:
69
- "3000:3000"
710
volumes:
@@ -16,7 +19,10 @@ services:
1619
- DISCLAIMER
1720
command: gunicorn -w 2 -b 0.0.0.0:3000 --log-file=- 'src.main:app'
1821
worker:
19-
build: .
22+
build:
23+
context: .
24+
# use Dockerfile.gpu when using a NVIDIA GPU
25+
dockerfile: Dockerfile
2026
volumes:
2127
- .:/workspace
2228
depends_on:
@@ -27,8 +33,15 @@ services:
2733
- EMAIL_SENDER_PASSWORD
2834
- EMAIL_SENDER_HOST
2935
command: rq worker --url redis://redis:6379 -c worker-settings
36+
# Uncomment the following lines when using a NVIDIA GPU
37+
# deploy:
38+
# resources:
39+
# reservations:
40+
# devices:
41+
# - driver: nvidia
42+
# capabilities: [gpu]
3043

3144
redis:
3245
image: redis
3346
ports:
34-
- "6379:6379"
47+
- "6379:6379"

0 commit comments

Comments
 (0)