Add GPU support with Docker enhancements

- Introduced a `Dockerfile.gpu` for GPU-enabled backend setup.
- Added `docker-compose.gpu.yml` to utilize GPU resources via NVIDIA.
- Fixed Nginx configuration for GPU backend port changes.
This commit is contained in:
Paper-Dragon
2025-07-04 00:16:39 +08:00
parent f667e9460b
commit 1ce8b41bde
3 changed files with 61 additions and 2 deletions

15
backend/Dockerfile.gpu Normal file
View File

@@ -0,0 +1,15 @@
FROM nvidia/cuda:12.6.0-cudnn-runtime-ubuntu24.04
RUN apt update && \
apt install -y ffmpeg python3-pip && \
apt clean all
# 设置 Hugging Face 镜像源环境变量
ENV HF_ENDPOINT=https://hf-mirror.com
WORKDIR /app
COPY ./backend /app
RUN pip install --no-cache-dir -i https://pypi.mirrors.ustc.edu.cn/simple -r requirements.txt --break-system-packages
RUN pip install --no-cache-dir -i https://pypi.mirrors.ustc.edu.cn/simple transformers[torch]>=4.23 --break-system-packages
CMD ["python3", "main.py"]

44
docker-compose.gpu.yml Normal file
View File

@@ -0,0 +1,44 @@
services:
backend:
container_name: bilinote-backend
build:
context: .
dockerfile: backend/Dockerfile.gpu
env_file:
- .env
environment:
- BACKEND_PORT=${BACKEND_PORT}
- BACKEND_HOST=${BACKEND_HOST}
volumes:
- ./backend:/app
expose:
- "${BACKEND_PORT}" # 不再对外暴露,用于 nginx 内部通信
deploy:
resources:
reservations:
devices:
- driver: "nvidia"
count: "all"
capabilities: ["gpu"]
frontend:
container_name: bilinote-frontend
build:
context: .
dockerfile: BillNote_frontend/Dockerfile
env_file:
- .env
expose:
- "80" # 不暴露给宿主机,只供 nginx 访问
nginx:
container_name: bilinote-nginx
image: nginx:1.25-alpine
ports:
- "${APP_PORT}:80"
volumes:
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- backend
- frontend

View File

@@ -8,13 +8,13 @@ server {
# 所有 /api 请求代理给 backend 容器
location /api/ {
proxy_pass http://backend:8000;
proxy_pass http://backend:8483;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location /static/ {
proxy_pass http://backend:8000/static/;
proxy_pass http://backend:8483/static/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;