-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.prod.yml
More file actions
106 lines (99 loc) · 3.2 KB
/
docker-compose.prod.yml
File metadata and controls
106 lines (99 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
version: "3.9"
services:
# MySQL数据库服务
mysql:
image: mysql:8.0
container_name: security-teaching-mysql
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-root}
MYSQL_DATABASE: ${MYSQL_DATABASE:-security_teaching_system}
MYSQL_USER: ${MYSQL_USER:-security_user}
MYSQL_PASSWORD: ${MYSQL_PASSWORD:-security_pass}
TZ: Asia/Shanghai
ports:
- "${MYSQL_PORT:-3306}:3306"
volumes:
- mysql_data:/var/lib/mysql
- ./scripts/init-db.sql:/docker-entrypoint-initdb.d/init-db.sql:ro
command:
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_unicode_ci
- --default-authentication-plugin=mysql_native_password
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p${MYSQL_ROOT_PASSWORD:-root}"]
interval: 10s
timeout: 5s
retries: 5
networks:
- security-network
# 后端服务(本地构建)
backend:
build:
context: .
dockerfile: Dockerfile.backend
image: javaweb-security-backend:latest
container_name: security-teaching-backend
restart: unless-stopped
depends_on:
mysql:
condition: service_healthy
environment:
SPRING_PROFILES_ACTIVE: docker
DB_URL: jdbc:mysql://mysql:3306/${MYSQL_DATABASE:-security_teaching_system}?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghai&allowMultiQueries=true&rewriteBatchedStatements=true&connectionCollation=utf8mb4_unicode_ci&characterSetResults=utf8mb4
DB_USERNAME: ${MYSQL_USER:-security_user}
DB_PASSWORD: ${MYSQL_PASSWORD:-security_pass}
MYSQL_HOST: mysql
MYSQL_PORT: 3306
MYSQL_DATABASE: ${MYSQL_DATABASE:-security_teaching_system}
MYSQL_USER: ${MYSQL_USER:-security_user}
MYSQL_PASSWORD: ${MYSQL_PASSWORD:-security_pass}
JWT_SECRET: ${JWT_SECRET:-change-me-in-production}
JAVA_OPTS: ${JAVA_OPTS:--Xms512m -Xmx1024m}
SERVER_PORT: 8080
CORS_ALLOWED_ORIGINS: ${CORS_ALLOWED_ORIGINS:-http://localhost:3000,http://localhost:80}
ports:
- "${BACKEND_PORT:-8080}:8080"
volumes:
- backend_logs:/app/logs
- backend_uploads:/app/uploads
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/actuator/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
networks:
- security-network
# 前端服务(本地构建)
frontend:
build:
context: .
dockerfile: Dockerfile.frontend
image: javaweb-security-frontend:latest
container_name: security-teaching-frontend
restart: unless-stopped
depends_on:
backend:
condition: service_healthy
ports:
- "${FRONTEND_PORT:-80}:80"
environment:
- BACKEND_URL=http://backend:8080
healthcheck:
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost/"]
interval: 30s
timeout: 10s
retries: 3
networks:
- security-network
volumes:
mysql_data:
driver: local
backend_logs:
driver: local
backend_uploads:
driver: local
networks:
security-network:
driver: bridge