nex_buddy/docker-compose.yml

67 lines
2.4 KiB
YAML
Raw Normal View History

2026-11-13 06:38:19 +00:00
name: nex-buddy
services:
api:
2026-11-13 08:40:28 +00:00
# 构建源与基础镜像默认值都在这里;服务器有差异时直接改本文件。
2026-11-13 06:38:19 +00:00
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}"
2026-11-13 07:01:11 +00:00
PYTHON_IMAGE: "${PYTHON_IMAGE:-python:3.12-slim}"
2026-11-13 06:38:19 +00:00
image: nex-buddy-api:latest
init: true
2026-11-13 08:23:00 +00:00
# 让容器通过 host.docker.internal 访问宿主机上的 PostgreSQL/Redis。
# 数据库在别的机器时,这条配置不会产生影响。
extra_hosts:
- "host.docker.internal:host-gateway"
2026-11-13 06:38:19 +00:00
env_file:
- .env
environment:
2026-11-13 07:01:11 +00:00
# 容器内固定使用 /app/data,宿主机路径由下面的 volumes 决定
2026-11-13 06:38:19 +00:00
DATA_DIR: /app/data
2026-11-13 08:40:28 +00:00
# 容器内端口固定;宿主机映射端口由 .env 的 BACKEND_PORT 决定
2026-11-13 08:51:05 +00:00
BACKEND_PORT: "8000"
2026-11-13 06:38:19 +00:00
FORWARDED_ALLOW_IPS: "*"
WEB_CONCURRENCY: "${WEB_CONCURRENCY:-2}"
volumes:
2026-11-13 08:40:28 +00:00
# 默认挂载项目根 data/;要换宿主机磁盘就改这里,或用 NEX_BUDDY_DATA_DIR 指定
2026-11-13 06:38:19 +00:00
- "${NEX_BUDDY_DATA_DIR:-./data}:/app/data"
2026-11-13 08:40:28 +00:00
ports:
2026-11-13 08:51:05 +00:00
# 宿主机端口由 .env 的 BACKEND_PORT 决定;容器内始终是 8000
2026-11-13 08:40:28 +00:00
- "${BACKEND_PORT:-8000}:8000"
2026-11-13 06:38:19 +00:00
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)"]
2026-11-13 06:38:19 +00:00
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}"
2026-11-13 08:27:02 +00:00
NODE_IMAGE: "${NODE_IMAGE:-node:22-alpine}"
NGINX_IMAGE: "${NGINX_IMAGE:-nginx:latest}"
2026-11-13 06:38:19 +00:00
image: nex-buddy-web:latest
ports:
2026-11-13 08:54:51 +00:00
# 宿主机端口由 .env 的 FRONTEND_PORT 决定;容器内 Nginx 始终是 80
- "${FRONTEND_PORT:-5173}:80"
2026-11-13 06:38:19 +00:00
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