version: '3.8' services: # MySQL数据库 mysql: image: mysql:8.0 container_name: emotion-mysql-prod restart: always environment: MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} MYSQL_DATABASE: ${MYSQL_DATABASE} MYSQL_USER: ${MYSQL_USER} MYSQL_PASSWORD: ${MYSQL_PASSWORD} TZ: ${TZ:-Asia/Shanghai} ports: - "3306:3306" volumes: - mysql_data:/var/lib/mysql - ./backend/mysql_emotion_museum_final.sql:/docker-entrypoint-initdb.d/init.sql - ./deploy/mysql/conf.d:/etc/mysql/conf.d - ./logs/mysql:/var/log/mysql command: --default-authentication-plugin=mysql_native_password networks: - emotion-network deploy: resources: limits: memory: 1G reservations: memory: 512M # Redis缓存 redis: image: redis:7-alpine container_name: emotion-redis-prod restart: always ports: - "6379:6379" volumes: - redis_data:/data - ./deploy/redis/redis.conf:/usr/local/etc/redis/redis.conf - ./logs/redis:/var/log/redis command: redis-server /usr/local/etc/redis/redis.conf networks: - emotion-network deploy: resources: limits: memory: 512M reservations: memory: 256M # Nacos注册中心 nacos: image: nacos/nacos-server:v2.2.0 container_name: emotion-nacos-prod restart: always environment: MODE: standalone SPRING_DATASOURCE_PLATFORM: mysql MYSQL_SERVICE_HOST: mysql MYSQL_SERVICE_DB_NAME: nacos_config MYSQL_SERVICE_PORT: 3306 MYSQL_SERVICE_USER: ${MYSQL_USER} MYSQL_SERVICE_PASSWORD: ${MYSQL_PASSWORD} MYSQL_SERVICE_DB_PARAM: characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false&allowPublicKeyRetrieval=true JVM_XMS: 512m JVM_XMX: 1024m JVM_XMN: 256m NACOS_AUTH_ENABLE: ${NACOS_AUTH_ENABLE:-false} ports: - "8848:8848" - "9848:9848" volumes: - nacos_data:/home/nacos/data - nacos_logs:/home/nacos/logs depends_on: - mysql networks: - emotion-network deploy: resources: limits: memory: 1.5G reservations: memory: 512M # 网关服务 gateway: build: context: ./backend dockerfile: ./emotion-gateway/Dockerfile image: emotion-gateway:latest container_name: emotion-gateway-prod restart: always ports: - "9000:9000" environment: SPRING_PROFILES_ACTIVE: docker NACOS_SERVER_ADDR: nacos:8848 MYSQL_HOST: mysql MYSQL_PORT: 3306 REDIS_HOST: redis REDIS_PORT: 6379 TZ: ${TZ:-Asia/Shanghai} volumes: - ./logs/gateway:/app/logs depends_on: - mysql - redis - nacos networks: - emotion-network deploy: resources: limits: memory: 1G reservations: memory: 512M # AI服务 ai-service: build: context: ./backend dockerfile: ./emotion-ai/Dockerfile image: emotion-ai:latest container_name: emotion-ai-prod restart: always ports: - "9002:9002" environment: SPRING_PROFILES_ACTIVE: docker NACOS_SERVER_ADDR: nacos:8848 MYSQL_HOST: mysql MYSQL_PORT: 3306 REDIS_HOST: redis REDIS_PORT: 6379 COZE_API_TOKEN: ${COZE_API_TOKEN} TZ: ${TZ:-Asia/Shanghai} volumes: - ./logs/ai:/app/logs depends_on: - mysql - redis - nacos networks: - emotion-network deploy: resources: limits: memory: 1G reservations: memory: 512M # 用户服务 user-service: build: context: ./backend dockerfile: ./emotion-user/Dockerfile image: emotion-user:latest container_name: emotion-user-prod restart: always ports: - "9001:9001" environment: SPRING_PROFILES_ACTIVE: docker NACOS_SERVER_ADDR: nacos:8848 MYSQL_HOST: mysql MYSQL_PORT: 3306 REDIS_HOST: redis REDIS_PORT: 6379 TZ: ${TZ:-Asia/Shanghai} volumes: - ./logs/user:/app/logs depends_on: - mysql - redis - nacos networks: - emotion-network deploy: resources: limits: memory: 1G reservations: memory: 512M # 前端应用 web: build: context: ./web dockerfile: Dockerfile args: BUILD_ENV: production image: emotion-web:latest container_name: emotion-web-prod restart: always ports: - "3000:80" volumes: - ./logs/web:/var/log/nginx depends_on: - gateway networks: - emotion-network deploy: resources: limits: memory: 256M reservations: memory: 128M # Nginx反向代理 nginx: image: nginx:alpine container_name: emotion-nginx-prod restart: always ports: - "80:80" - "443:443" volumes: - ./deploy/nginx/nginx.conf:/etc/nginx/nginx.conf - ./deploy/nginx/conf.d:/etc/nginx/conf.d - ./deploy/nginx/ssl:/etc/nginx/ssl - ./logs/nginx:/var/log/nginx depends_on: - web - gateway networks: - emotion-network deploy: resources: limits: memory: 256M reservations: memory: 128M volumes: mysql_data: driver: local redis_data: driver: local nacos_data: driver: local nacos_logs: driver: local networks: emotion-network: driver: bridge ipam: config: - subnet: 172.20.0.0/16