version: "3.8" services: # ---- PostgreSQL 数据库 ---- postgres: image: postgres:16-alpine container_name: miaosi-postgres environment: POSTGRES_USER: ${POSTGRES_USER:-postgres} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres} POSTGRES_DB: ${POSTGRES_DB:-miaosi} ports: - "${POSTGRES_PORT:-5432}:5432" volumes: - postgres_data:/var/lib/postgresql/data healthcheck: test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-postgres}"] interval: 5s timeout: 5s retries: 5 restart: unless-stopped # ---- Redis 缓存 / 消息队列 ---- redis: image: redis:7-alpine container_name: miaosi-redis ports: - "${REDIS_PORT:-6379}:6379" volumes: - redis_data:/data healthcheck: test: ["CMD", "redis-cli", "ping"] interval: 5s timeout: 5s retries: 5 restart: unless-stopped # ---- FastAPI 后端 ---- backend: build: context: ./backend dockerfile: Dockerfile container_name: miaosi-backend ports: - "${BACKEND_PORT:-8000}:8000" env_file: - ./backend/.env environment: # 覆盖数据库和 Redis 地址,指向 Docker 内部网络 DATABASE_URL: postgresql+asyncpg://${POSTGRES_USER:-postgres}:${POSTGRES_PASSWORD:-postgres}@postgres:5432/${POSTGRES_DB:-miaosi} REDIS_URL: redis://redis:6379/0 depends_on: postgres: condition: service_healthy redis: condition: service_healthy volumes: - video_temp:/tmp/videos restart: unless-stopped # ---- Next.js 前端 ---- frontend: build: context: ./frontend dockerfile: Dockerfile args: NEXT_PUBLIC_API_BASE_URL: ${NEXT_PUBLIC_API_BASE_URL:-http://localhost:8000} NEXT_PUBLIC_USE_MOCK: "false" container_name: miaosi-frontend ports: - "${FRONTEND_PORT:-3000}:3000" environment: NODE_ENV: production depends_on: - backend restart: unless-stopped volumes: postgres_data: redis_data: video_temp: