Files
ljwx-health/docker-compose.yml
2025-11-28 13:49:45 +08:00

318 lines
8.7 KiB
YAML

# LJWX 统一 Docker Compose 配置
# 包含业务应用、基础设施和监控系统
version: '3.8'
networks:
ljwx-network:
driver: bridge
volumes:
mysql_data:
driver: local
redis_data:
driver: local
prometheus_data:
driver: local
grafana_data:
driver: local
loki_data:
driver: local
alertmanager_data:
driver: local
services:
# ============================================
# 基础设施服务
# ============================================
# MySQL数据库
ljwx-mysql:
image: mysql:8.0
container_name: ljwx-mysql
environment:
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-root123456}
- MYSQL_DATABASE=${MYSQL_DATABASE:-ljwx}
- MYSQL_USER=${MYSQL_USER:-ljwx}
- MYSQL_PASSWORD=${MYSQL_PASSWORD:-ljwx123456}
volumes:
- mysql_data:/var/lib/mysql
- ./sql:/docker-entrypoint-initdb.d
ports:
- "3306:3306"
networks:
- ljwx-network
restart: unless-stopped
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p${MYSQL_ROOT_PASSWORD:-root123456}"]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s
# Redis缓存
ljwx-redis:
image: redis:7-alpine
container_name: ljwx-redis
command: redis-server --requirepass ${REDIS_PASSWORD:-redis123456}
volumes:
- redis_data:/data
ports:
- "6379:6379"
networks:
- ljwx-network
restart: unless-stopped
healthcheck:
test: ["CMD", "redis-cli", "--raw", "incr", "ping"]
interval: 10s
timeout: 3s
retries: 5
# ============================================
# 业务应用服务
# ============================================
# 后端服务 - ljwx-boot
ljwx-boot:
image: ljwx/boot:latest
container_name: ljwx-boot
build:
context: ./ljwx-boot/ljwx-boot-admin
dockerfile: Dockerfile
environment:
- SPRING_PROFILES_ACTIVE=prod
- MYSQL_DATABASE=${MYSQL_DATABASE:-ljwx}
- MYSQL_HOST=ljwx-mysql
- MYSQL_USER=${MYSQL_USER:-ljwx}
- MYSQL_PASSWORD=${MYSQL_PASSWORD:-ljwx123456}
- REDIS_HOST=ljwx-redis
- REDIS_PASSWORD=${REDIS_PASSWORD:-redis123456}
ports:
- "9998:9998"
depends_on:
ljwx-mysql:
condition: service_healthy
ljwx-redis:
condition: service_healthy
networks:
- ljwx-network
restart: unless-stopped
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9998/actuator/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
# 前端管理界面 - ljwx-admin
ljwx-admin:
image: ljwx/admin:latest
container_name: ljwx-admin
build:
context: ./ljwx-admin
dockerfile: Dockerfile
environment:
- NODE_ENV=development
- VITE_USER_NODE_ENV=development
- VITE_API_BASE_URL=http://ljwx-boot:9998
ports:
- "5173:5173"
depends_on:
ljwx-boot:
condition: service_healthy
networks:
- ljwx-network
restart: unless-stopped
# 大屏服务 - ljwx-bigscreen
ljwx-bigscreen:
image: ljwx/bigscreen:latest
container_name: ljwx-bigscreen
build:
context: ./ljwx-bigscreen/bigscreen
dockerfile: Dockerfile
environment:
- MYSQL_HOST=ljwx-mysql
- MYSQL_PORT=3306
- MYSQL_DATABASE=${MYSQL_DATABASE:-ljwx}
- MYSQL_USER=${MYSQL_USER:-ljwx}
- MYSQL_PASSWORD=${MYSQL_PASSWORD:-ljwx123456}
- REDIS_HOST=ljwx-redis
- REDIS_PORT=6379
- REDIS_PASSWORD=${REDIS_PASSWORD:-redis123456}
- API_BASE_URL=http://ljwx-boot:9998
ports:
- "5001:5001"
depends_on:
ljwx-boot:
condition: service_healthy
ljwx-mysql:
condition: service_healthy
ljwx-redis:
condition: service_healthy
networks:
- ljwx-network
restart: unless-stopped
# ============================================
# 监控系统服务
# ============================================
# Prometheus - 监控指标收集和存储
ljwx-prometheus:
image: prom/prometheus:latest
container_name: ljwx-prometheus
restart: unless-stopped
volumes:
- ./ljwx-bigscreen/bigscreen/monitoring/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
- ./ljwx-bigscreen/bigscreen/monitoring/prometheus/alerts.yml:/etc/prometheus/alerts.yml
- prometheus_data:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
- '--web.console.libraries=/usr/share/prometheus/console_libraries'
- '--web.console.templates=/usr/share/prometheus/consoles'
- '--web.enable-lifecycle'
- '--storage.tsdb.retention.time=30d'
ports:
- "9091:9090"
networks:
- ljwx-network
depends_on:
- ljwx-alertmanager
# Alertmanager - 告警管理和分发
ljwx-alertmanager:
image: prom/alertmanager:latest
container_name: ljwx-alertmanager
restart: unless-stopped
volumes:
- ./ljwx-bigscreen/bigscreen/monitoring/alertmanager/alertmanager.yml:/etc/alertmanager/alertmanager.yml
- alertmanager_data:/alertmanager
command:
- '--config.file=/etc/alertmanager/alertmanager.yml'
- '--storage.path=/alertmanager'
- '--web.external-url=http://localhost:9094'
ports:
- "9094:9093"
networks:
- ljwx-network
# Loki - 日志聚合系统
ljwx-loki:
image: grafana/loki:latest
container_name: ljwx-loki
restart: unless-stopped
volumes:
- ./ljwx-bigscreen/bigscreen/monitoring/loki/loki-config.yml:/etc/loki/loki-config.yml
- loki_data:/loki
command: -config.file=/etc/loki/loki-config.yml
ports:
- "3100:3100"
networks:
- ljwx-network
# Promtail - 日志采集器
ljwx-promtail:
image: grafana/promtail:latest
container_name: ljwx-promtail
restart: unless-stopped
volumes:
- ./ljwx-bigscreen/bigscreen/monitoring/promtail/promtail-config.yml:/etc/promtail/promtail-config.yml
- /tmp/bigscreen.log:/var/log/bigscreen/bigscreen.log:ro
- ./ljwx-bigscreen/bigscreen/bigscreen.log:/var/log/bigscreen/app.log:ro
command: -config.file=/etc/promtail/promtail-config.yml
networks:
- ljwx-network
depends_on:
- ljwx-loki
# Grafana - 可视化面板
ljwx-grafana:
image: grafana/grafana:latest
container_name: ljwx-grafana
restart: unless-stopped
volumes:
- ./ljwx-bigscreen/bigscreen/monitoring/grafana/provisioning:/etc/grafana/provisioning
- ./ljwx-bigscreen/bigscreen/monitoring/grafana/dashboards:/var/lib/grafana/dashboards
- grafana_data:/var/lib/grafana
environment:
- GF_SECURITY_ADMIN_USER=admin
- GF_SECURITY_ADMIN_PASSWORD=admin123
- GF_USERS_ALLOW_SIGN_UP=false
- GF_SERVER_ROOT_URL=http://localhost:3001
- GF_INSTALL_PLUGINS=grafana-piechart-panel
ports:
- "3001:3000"
networks:
- ljwx-network
depends_on:
- ljwx-prometheus
- ljwx-loki
# Node Exporter - 系统指标导出器
ljwx-node-exporter:
image: prom/node-exporter:latest
container_name: ljwx-node-exporter
restart: unless-stopped
command:
- '--path.procfs=/host/proc'
- '--path.sysfs=/host/sys'
- '--path.rootfs=/host'
- '--collector.filesystem.mount-points-exclude=^/(sys|proc|dev|host|etc)($$|/)'
volumes:
- /proc:/host/proc:ro
- /sys:/host/sys:ro
- /:/host:ro
ports:
- "9101:9100"
networks:
- ljwx-network
# ============================================
# 使用说明
# ============================================
#
# 1. 创建 .env 文件配置环境变量(可选):
# MYSQL_ROOT_PASSWORD=your_root_password
# MYSQL_PASSWORD=your_user_password
# REDIS_PASSWORD=your_redis_password
#
# 2. 启动所有服务:
# docker-compose up -d
#
# 3. 启动特定服务:
# docker-compose up -d ljwx-mysql ljwx-redis ljwx-boot
#
# 4. 查看服务状态:
# docker-compose ps
#
# 5. 查看服务日志:
# docker-compose logs -f [service-name]
#
# 6. 停止所有服务:
# docker-compose down
#
# 7. 停止并删除数据卷(谨慎操作):
# docker-compose down -v
#
# ============================================
# 服务访问地址
# ============================================
#
# 业务应用:
# - 后端API: http://localhost:9998
# - 管理界面: http://localhost:5173
# - 大屏服务: http://localhost:5001
#
# 基础设施:
# - MySQL: localhost:3306
# - Redis: localhost:6379
#
# 监控系统:
# - Grafana: http://localhost:3001 (admin/admin123)
# - Prometheus: http://localhost:9091
# - Alertmanager: http://localhost:9094
# - Loki: http://localhost:3100
# - Node Exporter: http://localhost:9101
#