From 34a511e36e7209008edf302901ba59e7fc022e3a Mon Sep 17 00:00:00 2001 From: ViperEkura <3081035982@qq.com> Date: Sat, 9 May 2026 11:57:46 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=20Docker=20Compose?= =?UTF-8?q?=20=E4=B8=80=E9=94=AE=E9=83=A8=E7=BD=B2=EF=BC=8C=E6=94=AF?= =?UTF-8?q?=E6=8C=81=20GPU/CPU=20=E5=8F=8C=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + README.md | 8 +++++++ assets/docs/README-zh-CN.md | 6 ++++++ docker-compose.yml | 42 +++++++++++++++++++++++++++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 docker-compose.yml diff --git a/.gitignore b/.gitignore index d05cc85..9224a8c 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ !/.gitattributes !/.dockerignore !/Dockerfile +!/docker-compose.yml !/assets/** !/CONTRIBUTING.md !/LICENSE diff --git a/README.md b/README.md index d72d743..295b479 100644 --- a/README.md +++ b/README.md @@ -114,10 +114,18 @@ docker run --gpus all -p 8000:8000 astrai:latest \ # Run with volume mount for data docker run --gpus all -v /path/to/data:/data -it astrai:latest + +# Docker Compose (GPU, default) +docker compose up -d + +# Docker Compose (CPU only) +docker compose --profile cpu up -d ``` > **Note**: `--gpus all` is required for CUDA support. Without it, `torch.cuda.is_available()` will return `False`. +> **Note**: `--gpus all` is required for CUDA support. Without it, `torch.cuda.is_available()` will return `False`. + #### Start HTTP Server Start the inference server with OpenAI and Anthropic-compatible HTTP API: diff --git a/assets/docs/README-zh-CN.md b/assets/docs/README-zh-CN.md index 92f9e96..c0256f4 100644 --- a/assets/docs/README-zh-CN.md +++ b/assets/docs/README-zh-CN.md @@ -120,6 +120,12 @@ docker run --gpus all -p 8000:8000 astrai:latest \ # 挂载数据卷 docker run --gpus all -v /path/to/data:/data -it astrai:latest + +# Docker Compose(GPU,默认) +docker compose up -d + +# Docker Compose(仅 CPU) +docker compose --profile cpu up -d ``` > **注意**: 必须使用 `--gpus all` 才能启用 CUDA 支持,否则 `torch.cuda.is_available()` 将返回 `False`。 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..225bc5b --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,42 @@ +services: + server: + build: . + image: astrai:latest + ports: + - "8000:8000" + volumes: + - ./params:/app/params:ro + - ./checkpoints:/app/checkpoints + command: python -m scripts.tools.server --port 8000 --device cuda + deploy: + resources: + reservations: + devices: + - driver: nvidia + count: 1 + capabilities: [gpu] + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:8000/health"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 60s + restart: unless-stopped + + server-cpu: + profiles: [cpu] + build: . + image: astrai:latest + ports: + - "8000:8000" + volumes: + - ./params:/app/params:ro + - ./checkpoints:/app/checkpoints + command: python -m scripts.tools.server --port 8000 --device cpu + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:8000/health"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 120s + restart: unless-stopped