-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
138 lines (131 loc) · 3.41 KB
/
docker-compose.yml
File metadata and controls
138 lines (131 loc) · 3.41 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
services:
# Redis缓存服务
redis:
image: redis:7-alpine
container_name: bastion-redis
restart: unless-stopped
command: redis-server --appendonly yes
networks:
- bastion-network
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 30s
timeout: 3s
start_period: 10s
retries: 3
# MySQL数据库服务
mysql:
build:
context: .
dockerfile: docker/mysql/Dockerfile
container_name: bastion-mysql
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: password123
MYSQL_DATABASE: bastion
TZ: Asia/Shanghai
networks:
- bastion-network
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-ppassword123"]
interval: 30s
timeout: 3s
start_period: 30s
retries: 3
# 后端API服务
backend:
build:
context: .
dockerfile: docker/backend/Dockerfile
container_name: bastion-backend
restart: unless-stopped
depends_on:
mysql:
condition: service_healthy
redis:
condition: service_healthy
# 移除端口映射,不需要对外暴露
environment:
TZ: Asia/Shanghai
DB_HOST: mysql # 使用服务名连接数据库
REDIS_HOST: redis # 使用服务名连接Redis
networks:
- bastion-network
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:8080/api/v1/health"]
interval: 30s
timeout: 3s
start_period: 30s
retries: 3
# 前端Web服务
frontend:
build:
context: .
dockerfile: docker/frontend/Dockerfile
args:
# 使用nginx代理时不需要设置API URL
REACT_APP_API_URL: ""
container_name: bastion-frontend
restart: unless-stopped
depends_on:
- backend
ports:
- "8080:80" # 唯一需要对外暴露的端口
environment:
TZ: Asia/Shanghai
networks:
- bastion-network
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost/"]
interval: 30s
timeout: 3s
start_period: 10s
retries: 3
# SSH测试服务器1
ssh-server-1:
build:
context: .
dockerfile: docker/ssh-server/Dockerfile
container_name: bastion-ssh-server-1
restart: unless-stopped
hostname: ssh-server-1
environment:
TZ: Asia/Shanghai
networks:
bastion-network:
ipv4_address: 172.20.0.10
healthcheck:
test: ["CMD", "service", "ssh", "status"]
interval: 30s
timeout: 3s
start_period: 10s
retries: 3
# SSH测试服务器2
ssh-server-2:
build:
context: .
dockerfile: docker/ssh-server/Dockerfile
container_name: bastion-ssh-server-2
restart: unless-stopped
hostname: ssh-server-2
environment:
TZ: Asia/Shanghai
networks:
bastion-network:
ipv4_address: 172.20.0.11
healthcheck:
test: ["CMD", "service", "ssh", "status"]
interval: 30s
timeout: 3s
start_period: 10s
retries: 3
# 自定义网络配置
networks:
bastion-network:
driver: bridge
ipam:
driver: default
config:
- subnet: 172.20.0.0/16
gateway: 172.20.0.1
# 注意:根据需求,不使用volumes进行持久化存储