挂载更新

This commit is contained in:
2025-11-24 14:33:02 +08:00
parent a92dc6180d
commit 054eac0987
10 changed files with 438 additions and 182 deletions

View File

@@ -15,7 +15,7 @@ services:
ports:
- "${MYSQL_PORT:-3306}:3306"
volumes:
# 数据持久化
# 数据持久化(命名卷)
- mysql-data:/var/lib/mysql
# 自定义配置文件(可选,取消注释以启用)
# 如需自定义MySQL配置取消下面的注释并修改mysql/my.cnf
@@ -45,8 +45,10 @@ services:
ports:
- "${REDIS_PORT:-6379}:6379"
volumes:
# 数据持久化(命名卷)
- redis-data:/data
- ./redis/redis.conf:/usr/local/etc/redis/redis.conf
# Redis配置文件命名卷
- redis-config:/usr/local/etc/redis
command: redis-server /usr/local/etc/redis/redis.conf --requirepass ${REDIS_PASSWORD:-123456}
networks:
- school-news-network
@@ -83,15 +85,15 @@ services:
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
# 配置文件(命名卷)
- serv-config:/app/config
# 日志目录(命名卷)
- serv-logs:/app/logs
# 上传文件目录(命名卷)
- serv-uploads:/app/uploads
# 爬虫脚本目录(默认不挂载,保留在镜像内)
# 注意:挂载会覆盖镜像内容,如需运行时更新爬虫脚本可取消注释
- serv-crawler:/app/crawler
networks:
- school-news-network
healthcheck:
@@ -101,7 +103,7 @@ services:
retries: 3
start_period: 60s
# 前端服务
# 前端服务Node + Vite Preview
school-news-web:
image: school-news-web:latest
container_name: school-news-web
@@ -110,17 +112,45 @@ services:
- school-news-serv
environment:
TZ: Asia/Shanghai
ports:
- "${WEB_PORT:-8080}:80"
NODE_ENV: production
# 不直接暴露端口通过nginx反向代理访问
expose:
- "4173"
volumes:
# 运行时配置文件挂载(可整个替换,修改后重启容器即可生效
- ./config/web-app-config.js:/app/config/app-config.js
# 日志目录挂载
- ./logs/web:/app/logs
# 运行时配置文件(命名卷
- web-config:/app/config
# 日志目录(命名卷)
- web-logs:/app/logs
networks:
- school-news-network
healthcheck:
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost/schoolNewsWeb/"]
test: ["CMD", "curl", "-f", "http://localhost:4173/"]
interval: 30s
timeout: 10s
retries: 3
start_period: 20s
# Nginx反向代理
nginx:
image: nginx:alpine # 直接使用官方镜像,无需自定义构建
container_name: school-news-nginx
restart: always
depends_on:
- school-news-web
- school-news-serv
environment:
TZ: Asia/Shanghai
ports:
- "${NGINX_PORT:-80}:80"
volumes:
# Nginx配置文件命名卷
- nginx-config:/etc/nginx:ro
# 日志目录(命名卷)
- nginx-logs:/var/log/nginx
networks:
- school-news-network
healthcheck:
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost/"]
interval: 30s
timeout: 10s
retries: 3
@@ -130,8 +160,89 @@ networks:
school-news-network:
driver: bridge
# 命名卷定义数据存储在当前目录下的volumes/子目录)
# 使用前请先运行初始化脚本:./init-volumes.sh 或 init-volumes.bat
volumes:
# ===== MySQL =====
mysql-data:
driver: local
driver_opts:
type: none
o: bind
device: ./volumes/mysql/data
# ===== Redis =====
redis-data:
driver: local
driver_opts:
type: none
o: bind
device: ./volumes/redis/data
redis-config:
driver: local
driver_opts:
type: none
o: bind
device: ./volumes/redis/config
# ===== 后端服务 =====
serv-config:
driver: local
driver_opts:
type: none
o: bind
device: ./volumes/serv/config
serv-logs:
driver: local
driver_opts:
type: none
o: bind
device: ./volumes/serv/logs
serv-uploads:
driver: local
driver_opts:
type: none
o: bind
device: ./volumes/serv/uploads
# 爬虫脚本目录(可选,默认不启用)
# 注意启用后会覆盖镜像内的爬虫脚本需先复制镜像内容到volumes/serv/crawler
serv-crawler:
driver: local
driver_opts:
type: none
o: bind
device: ./volumes/serv/crawler
# ===== 前端服务 =====
web-config:
driver: local
driver_opts:
type: none
o: bind
device: ./volumes/web/config
web-logs:
driver: local
driver_opts:
type: none
o: bind
device: ./volumes/web/logs
# ===== Nginx =====
nginx-config:
driver: local
driver_opts:
type: none
o: bind
device: ./volumes/nginx/config
nginx-logs:
driver: local
driver_opts:
type: none
o: bind
device: ./volumes/nginx/logs