docker-compose.yml

2.2 KB v1.0
name: yunke-crm-pro

services:
  # ---------- PostgreSQL ----------
  db:
    image: postgres:16-alpine
    container_name: crm-pro-db
    restart: unless-stopped
    environment:
      POSTGRES_USER: crm
      POSTGRES_PASSWORD: ${PG_PASSWORD:?请先在 .env 设置 PG_PASSWORD}
      POSTGRES_DB: crm
      TZ: Asia/Shanghai
    volumes:
      - pgdata:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U crm -d crm"]
      interval: 5s
      timeout: 5s
      retries: 12
      start_period: 10s
    logging:
      driver: json-file
      options: { max-size: "10m", max-file: "3" }

  # ---------- 后端 API ----------
  api:
    build:
      context: ./server
      dockerfile: Dockerfile
    container_name: crm-pro-api
    restart: unless-stopped
    environment:
      PORT: 3001
      CORS_ORIGIN: ${CORS_ORIGIN:-http://localhost:8080}
      JWT_SECRET: ${JWT_SECRET:?请先在 .env 设置 JWT_SECRET}
      JWT_EXPIRES_IN: 7d
      DB_DRIVER: postgres
      PG_HOST: db
      PG_PORT: 5432
      PG_USER: crm
      PG_PASSWORD: ${PG_PASSWORD:?请先在 .env 设置 PG_PASSWORD}
      PG_DATABASE: crm
      EMAIL_DEV_MODE: ${EMAIL_DEV_MODE:-true}
      TZ: Asia/Shanghai
      # 超级管理员初始账号(仅首次启动生效,已存在则跳过)
      SUPER_ADMIN_USERNAME: ${SUPER_ADMIN_USERNAME:-admin}
      SUPER_ADMIN_PASSWORD: ${SUPER_ADMIN_PASSWORD:-admin123456}
    depends_on:
      db:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "node", "-e", "fetch('http://127.0.0.1:3001/api/health').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"]
      interval: 10s
      timeout: 5s
      retries: 12
      start_period: 40s
    logging:
      driver: json-file
      options: { max-size: "10m", max-file: "3" }

  # ---------- 前端 ----------
  web:
    build:
      context: ./client
      dockerfile: Dockerfile
    container_name: crm-pro-web
    restart: unless-stopped
    ports:
      - "${WEB_PORT:-8080}:80"
    depends_on:
      api:
        condition: service_healthy
    logging:
      driver: json-file
      options: { max-size: "10m", max-file: "3" }

volumes:
  pgdata:
    name: crm-pro-pgdata