67 lines
2.4 KiB
YAML
67 lines
2.4 KiB
YAML
name: nex-buddy
|
||
|
||
services:
|
||
api:
|
||
# 构建源与基础镜像默认值都在这里;服务器有差异时直接改本文件。
|
||
build:
|
||
context: .
|
||
dockerfile: docker/Dockerfile.api
|
||
args:
|
||
APT_MIRROR: "${APT_MIRROR:-mirrors.tuna.tsinghua.edu.cn}"
|
||
PIP_INDEX_URL: "${PIP_INDEX_URL:-https://pypi.tuna.tsinghua.edu.cn/simple}"
|
||
PYTHON_IMAGE: "${PYTHON_IMAGE:-python:3.12-slim}"
|
||
image: nex-buddy-api:latest
|
||
init: true
|
||
# 让容器通过 host.docker.internal 访问宿主机上的 PostgreSQL/Redis。
|
||
# 数据库在别的机器时,这条配置不会产生影响。
|
||
extra_hosts:
|
||
- "host.docker.internal:host-gateway"
|
||
env_file:
|
||
- .env
|
||
environment:
|
||
# 容器内固定使用 /app/data,宿主机路径由下面的 volumes 决定
|
||
DATA_DIR: /app/data
|
||
# 容器内端口固定;宿主机映射端口由 .env 的 BACKEND_PORT 决定
|
||
BACKEND_PORT: "8000"
|
||
FORWARDED_ALLOW_IPS: "*"
|
||
WEB_CONCURRENCY: "${WEB_CONCURRENCY:-2}"
|
||
volumes:
|
||
# 默认挂载项目根 data/;要换宿主机磁盘就改这里,或用 NEX_BUDDY_DATA_DIR 指定
|
||
- "${NEX_BUDDY_DATA_DIR:-./data}:/app/data"
|
||
ports:
|
||
# 宿主机端口由 .env 的 BACKEND_PORT 决定;容器内始终是 8000
|
||
- "${BACKEND_PORT:-8000}:8000"
|
||
restart: unless-stopped
|
||
healthcheck:
|
||
test: ["CMD", "python", "-c", "import json,urllib.request; d=json.load(urllib.request.urlopen('http://127.0.0.1:8000/healthz', timeout=5)); raise SystemExit(0 if d.get('ok') else 1)"]
|
||
interval: 10s
|
||
timeout: 5s
|
||
retries: 20
|
||
start_period: 30s
|
||
|
||
web:
|
||
build:
|
||
context: .
|
||
dockerfile: docker/Dockerfile.web
|
||
args:
|
||
NPM_REGISTRY: "${NPM_REGISTRY:-https://registry.npmmirror.com}"
|
||
NODE_IMAGE: "${NODE_IMAGE:-node:22-alpine}"
|
||
NGINX_IMAGE: "${NGINX_IMAGE:-nginx:latest}"
|
||
image: nex-buddy-web:latest
|
||
ports:
|
||
# 宿主机端口由 .env 的 FRONTEND_PORT 决定;容器内 Nginx 始终是 80
|
||
- "${FRONTEND_PORT:-5173}:80"
|
||
depends_on:
|
||
api:
|
||
condition: service_healthy
|
||
restart: unless-stopped
|
||
|
||
networks:
|
||
default:
|
||
name: nex-buddy_default
|
||
ipam:
|
||
config:
|
||
# 避开办公网 192.168.2.0/24;Docker 自动分配过 192.168.0.0/20,
|
||
# 会让容器把客户端当成同网段直连,导致端口映射握手超时。
|
||
- subnet: 172.30.0.0/24
|