# ================================================== # OCDP Docker Compose (frontend + gateway layer) # ================================================== # 使用方式: # docker compose -f docker-compose.yml \ # -f ./backend/docker-compose.yml \ # --profile backend up --build -d # # 说明: # - 本文件只负责前端构建和 Nginx。 # - Backend / PostgreSQL / pgAdmin 由 backend/docker-compose.yml 提供。 # - Nginx 统一监听 80/443(默认映射 WEB_HTTP_PORT=80、WEB_HTTPS_PORT=443), # 根据路径转发:/api/* → backend,其他路径 → 前端服务。 # ================================================== services: # -------------------------------------------------- # Next.js 前端服务 # -------------------------------------------------- frontend: image: node:20-alpine container_name: ocdp-frontend init: true working_dir: /app restart: unless-stopped environment: NODE_ENV: production NEXT_PUBLIC_API_URL: ${NEXT_PUBLIC_API_URL:-/api/v1} command: sh -c "npm install --include=dev && npm run build && npm run start" expose: - "3000" volumes: - ./frontend:/app - frontend_node_modules:/app/node_modules networks: - ocdp-network healthcheck: test: ["CMD-SHELL", "wget -qO- http://localhost:3000 || exit 1"] interval: 30s timeout: 10s retries: 3 # -------------------------------------------------- # Nginx - 静态文件 + /api 反向代理统一入口 # -------------------------------------------------- nginx: image: nginx:1.27-alpine container_name: ocdp-nginx depends_on: frontend: condition: service_started ports: - "${WEB_HTTP_PORT:-80}:80" - "${WEB_HTTPS_PORT:-443}:443" volumes: - ./infra/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro - ./infra/nginx/certs:/etc/nginx/certs:ro healthcheck: test: ["CMD-SHELL", "wget -qO- http://localhost/healthz || exit 1"] interval: 30s timeout: 5s retries: 5 networks: - ocdp-network # ================================================== # Networks # ================================================== networks: ocdp-network: driver: bridge name: ocdp-network # ================================================== # Volumes # ================================================== volumes: frontend_node_modules: driver: local