version: '3.8'

services:
  # MySQL 服务(可选，如果需要可以取消注释）
  # mysql:
  #   image: mysql:8.0
  #   container_name: mysql-container
  #   restart: on-failure
  #   environment:
  #     MYSQL_ROOT_PASSWORD: root
  #     MYSQL_DATABASE: mydb
  #   ports:
  #     - "3306:3306"
  #   volumes:
  #     - mysql-data:/var/lib/mysql
  #   networks:
  #     - app-network

  # API 服务
  api:
    image: container-api:latest
    container_name: api-container
    restart: on-failure
    environment:
      - NODE_ENV=prod
      # 数据库连接信息(连接到外部 MySQL 容器）
      - MYSQL_HOST=host.docker.internal
      - MYSQL_PORT=23306
      - MYSQL_USERNAME=root
      - MYSQL_PASSWORD=root
      - MYSQL_DATABASE=inventory
    ports:
      - "7001:7001"
    networks:
      - app-network

  # WEB 服务
  web:
    image: container-web:latest
    container_name: web-container
    restart: on-failure
    environment:
      - NODE_ENV=prod
    ports:
      - "8080:80"
    depends_on:
      - api
    networks:
      - app-network

# volumes:
#   mysql-data:
#     driver: local

networks:
  app-network:
    driver: bridge
