Files
schoolNews/docker/docker-compose.yml
2025-11-24 12:59:51 +08:00

138 lines
3.8 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

version: '3.8'
services:
# MySQL数据库
mysql:
image: school-news-mysql:latest
container_name: school-news-mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-123456}
MYSQL_DATABASE: ${MYSQL_DATABASE:-school_news}
MYSQL_USER: ${MYSQL_USER:-schoolnews}
MYSQL_PASSWORD: ${MYSQL_PASSWORD:-123456}
TZ: Asia/Shanghai
ports:
- "${MYSQL_PORT:-3306}:3306"
volumes:
# 数据持久化
- mysql-data:/var/lib/mysql
# 自定义配置文件(可选,取消注释以启用)
# 如需自定义MySQL配置取消下面的注释并修改mysql/my.cnf
# - ./mysql/my.cnf:/etc/mysql/conf.d/my.cnf
command:
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_unicode_ci
- --default-authentication-plugin=mysql_native_password
- --max_connections=1000
- --max_allowed_packet=64M
networks:
- school-news-network
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-p${MYSQL_ROOT_PASSWORD:-123456}"]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s
# Redis缓存
redis:
image: redis:7-alpine
container_name: school-news-redis
restart: always
environment:
TZ: Asia/Shanghai
ports:
- "${REDIS_PORT:-6379}:6379"
volumes:
- redis-data:/data
- ./redis/redis.conf:/usr/local/etc/redis/redis.conf
command: redis-server /usr/local/etc/redis/redis.conf --requirepass ${REDIS_PASSWORD:-123456}
networks:
- school-news-network
healthcheck:
test: ["CMD", "redis-cli", "--raw", "incr", "ping"]
interval: 10s
timeout: 3s
retries: 5
# 后端服务
school-news-serv:
image: school-news-serv:latest
container_name: school-news-serv
restart: always
depends_on:
mysql:
condition: service_healthy
redis:
condition: service_healthy
environment:
# 数据库配置
MYSQL_HOST: mysql
MYSQL_PORT: 3306
MYSQL_DATABASE: ${MYSQL_DATABASE:-school_news}
MYSQL_USER: ${MYSQL_USER:-root}
MYSQL_PASSWORD: ${MYSQL_PASSWORD:-123456}
# Redis配置
REDIS_HOST: redis
REDIS_PORT: 6379
REDIS_PASSWORD: ${REDIS_PASSWORD:-123456}
# JVM配置
JAVA_OPTS: "-Xms512m -Xmx1g -XX:+UseG1GC"
TZ: Asia/Shanghai
ports:
- "${SERV_PORT:-8081}:8081"
volumes:
# 配置文件挂载
- ./config/application.yml:/app/config/application.yml
- ./config/log4j2-spring.xml:/app/config/log4j2-spring.xml
# 日志目录挂载
- ./logs/serv:/app/logs
# 上传文件目录
- ./uploads:/app/uploads
# 爬虫脚本目录(如果需要更新爬虫脚本)
- ../schoolNewsCrawler:/app/crawler
networks:
- school-news-network
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8081/schoolNewsServ/actuator/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
# 前端服务
school-news-web:
image: school-news-web:latest
container_name: school-news-web
restart: always
depends_on:
- school-news-serv
environment:
TZ: Asia/Shanghai
ports:
- "${WEB_PORT:-8080}:80"
volumes:
# 运行时配置文件挂载(可整个替换,修改后重启容器即可生效)
- ./config/web-app-config.js:/app/config/app-config.js
# 日志目录挂载
- ./logs/web:/app/logs
networks:
- school-news-network
healthcheck:
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost/schoolNewsWeb/"]
interval: 30s
timeout: 10s
retries: 3
start_period: 10s
networks:
school-news-network:
driver: bridge
volumes:
mysql-data:
driver: local
redis-data:
driver: local