-
Notifications
You must be signed in to change notification settings - Fork 11
/
docker-compose.yml
385 lines (349 loc) · 16 KB
/
docker-compose.yml
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
version: '3.2' # 选择 docker-compose 项目版本号
services:
redis:
build:
context: ./DockerFiles/redis
dockerfile: Dockerfile
# image: nginx # 镜像名称
container_name: redis_container # 容器名字
restart: always # 开机自动重启
ports:
- '${REDIS_PORT}:${REDIS_PORT}'
expose:
- ${REDIS_PORT} # 暴露出端口 给links使用
networks:
- app
# networks:
# app:
# #当前服务器使用哪个桥
# ipv4_address: 172.16.0.2 # 具体ip
# - ./nginx/nginx.conf:/etc/nginx/nginx.conf #配置文件
# - ./log:/var/log/nginx ###这里面放置日志
# - ./html:/html ###这里面放置项目目录
# command: "redis-server /usr/local/etc/redis/redis.conf" # 覆盖 Dockerfile 中的 cmd
# env_file:
# - ot-system-server/.env.production
mysql:
# image: "mysql:5.7" #获取mysql 镜像
build:
context: ./DockerFiles/mysql
dockerfile: Dockerfile
container_name: mysql_container #mysql容器名称 docker run --name mysql
restart: always # docker启动,当前容器必启动
ports:
- "${MYSQL_PORT}:${MYSQL_PORT}" # 容器外部导出端口号:容器内部端口号
expose:
- ${MYSQL_PORT} # 暴露出端口 给links使用
# network_mode: "host" #https://juejin.cn/post/6844904056301830152
networks:
- app
# networks:
# app:
# #当前服务器使用哪个桥
# ipv4_address: 172.16.0.3 # 具体ip
environment:
#代表了给当前容器指定环境 相当于 docker run -e MYSQL_ROOT_PASSWORD: "123456"
# MYSQL_USER: 'root' # mysql 用户名
# MYSQL_PASS: '123456' # mysql 密码
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} # mysql 密码
# volumes:
# # 代表给当前容器和宿主机指定数据卷, 类似于docker run -v
# - /root/mysql_data:/var/lib/mysql # 绝对路径映射 映射多个数据卷 类似于docker run -v 注意:docker-compose使用绝对路劲要求必须先创建才能使用
# - ./data:/var/lib/mysql # 映射多个数据卷 类似于docker run -v 注意:docker-compose使用绝对路劲要求必须先创建才能使用
# env_file:
# - ot-system-server/.env.production
server:
# image: "node:14" #获取node镜像
build:
context: ./ot-system-server
args:
#将配置文件传入到 dockerfile 文件中
REDIS_ADDRESS: ${REDIS_ADDRESS} # redis ip
REDIS_PORT: ${REDIS_PORT} # redis 端口
MYSQL_ADDRESS: ${MYSQL_ADDRESS} # mysql ip
MYSQL_PORT: ${MYSQL_PORT} # mysql 端口
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} # mysql 密码
SERVER_ADDRESS: ${SERVER_ADDRESS} # serverip
SERVER_PORT: ${SERVER_PORT} # server 端口
SERVER_NODE_ENV: ${SERVER_NODE_ENV} # server NODE_ENV
CLIENT_ADDRESS: ${CLIENT_ADDRESS} # client ip
CLIENT_PORT: ${CLIENT_PORT} # client 端口
CLIENT_SERVER_NAME: ${CLIENT_SERVER_NAME}
CLIENT_PUBLICPATH: ${CLIENT_PUBLICPATH}
ADMIN_ADDRESS: ${ADMIN_ADDRESS} # admin ip
ADMIN_PORT: ${ADMIN_PORT} # admin 端口
ADMIN_SERVER_NAME: ${ADMIN_SERVER_NAME}
ADMIN_PUBLICPATH: ${ADMIN_PUBLICPATH}
ENTRY_ADDRESS: ${ENTRY_ADDRESS} # ENTRY ip
ENTRY_PORT: ${ENTRY_PORT} # ENTRY 端口
ENTRY_SERVER_NAME: ${ENTRY_SERVER_NAME}
dockerfile: Dockerfile
container_name: server_container #mysql容器名称 docker run --name mysql
restart: always # docker启动,当前容器必启动
ports:
- "${SERVER_PORT}:${SERVER_PORT}" # 容器外部导出端口号:容器内部端口号
expose:
- ${SERVER_PORT} # 暴露出端口 给links使用
networks:
- app
# networks:
# app:
# #当前服务器使用哪个桥
# ipv4_address: 172.16.0.4 # 具体ip
links:
- mysql # 这里是 services 名称而不是容器名称 可以不用 links参数也是可以的
- redis # 网络连接到redis services中
depends_on:
#优先启动mysql和redis
- mysql # 这里是 services 名称而 不是容器名称
- redis # 这里是 services 名称而 不是容器名称
#启动服务
command: "npm run prd:n"
# 覆盖 Dockerfile 中的 cmd
# environment:
# #代表了给当前容器指定环境 相当于 docker run -e MYSQL_ROOT_PASSWORD: "123456"
# # MYSQL_USER: 'root' # mysql 用户名
# # MYSQL_PASS: '123456' # mysql 密码
# MYSQL_ROOT_PASSWORD: "123456" # mysql 密码
# volumes:
# # 代表给当前容器和宿主机指定数据卷, 类似于docker run -v
# - /root/mysql_data:/var/lib/mysql # 绝对路径映射 映射多个数据卷 类似于docker run -v 注意:docker-compose使用绝对路劲要求必须先创建才能使用
# # - ./data:/var/lib/mysql # 映射多个数据卷 类似于docker run -v 注意:docker-compose使用绝对路劲要求必须先创建才能使用
# env_file:
# - ot-system-server/.env.production
client:
build:
context: ./ot-system-client
args:
#将配置文件传入到 dockerfile 文件中
REDIS_ADDRESS: ${REDIS_ADDRESS} # redis ip
REDIS_PORT: ${REDIS_PORT} # redis 端口
MYSQL_ADDRESS: ${MYSQL_ADDRESS} # mysql ip
MYSQL_PORT: ${MYSQL_PORT} # mysql 端口
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} # mysql 密码
SERVER_ADDRESS: ${SERVER_ADDRESS} # serverip
SERVER_PORT: ${SERVER_PORT} # server 端口
CLIENT_ADDRESS: ${CLIENT_ADDRESS} # client ip
CLIENT_PORT: ${CLIENT_PORT} # client 端口
CLIENT_SERVER_NAME: ${CLIENT_SERVER_NAME}
CLIENT_PUBLICPATH: ${CLIENT_PUBLICPATH}
CLIENT_RENDER: ${CLIENT_RENDER}
CLIENT_NODE_ENV: ${CLIENT_NODE_ENV}
ADMIN_ADDRESS: ${ADMIN_ADDRESS} # admin ip
ADMIN_PORT: ${ADMIN_PORT} # admin 端口
ADMIN_SERVER_NAME: ${ADMIN_SERVER_NAME}
ADMIN_PUBLICPATH: ${ADMIN_PUBLICPATH}
ENTRY_ADDRESS: ${ENTRY_ADDRESS} # ENTRY ip
ENTRY_PORT: ${ENTRY_PORT} # ENTRY 端口
ENTRY_SERVER_NAME: ${ENTRY_SERVER_NAME}
dockerfile: Dockerfile
# image: nginx # 镜像名称
container_name: client_container # 容器名字
restart: always # 开机自动重启
ports:
- ${CLIENT_PORT}:${CLIENT_PORT} # 主机端口:容器端口
expose:
- ${CLIENT_PORT} # 暴露出端口 给links使用
# environment:
# - NGINX_HOST=foobar.com
# - NGINX_PORT=80
# - CLIENT=client
networks:
- app
# networks:
# app:
# #当前服务器使用哪个桥
# ipv4_address: 172.16.0.2 # 具体ip
# - ./nginx/nginx.conf:/etc/nginx/nginx.conf #配置文件
# - ./log:/var/log/nginx ###这里面放置日志
# - ./html:/html ###这里面放置项目目录
links:
- server # 网络连接到server中
depends_on:
- server
environment:
# 是环境变量
- CLIENT_ADDRESS=${CLIENT_ADDRESS} # client ip
- CLIENT_PORT=${CLIENT_PORT} # client 端口
- CLIENT_SERVER_NAME=${CLIENT_SERVER_NAME} # client SERVER
- ADMIN_ADDRESS=${ADMIN_ADDRESS} # admin ip
- ADMIN_PORT=${ADMIN_PORT} # admin 端口
- ENTRY_PORT=${ENTRY_PORT} #nginx 端口号
- ENTRY_SERVER_NAME=${ENTRY_SERVER_NAME}
- CLIENT_PUBLICPATH=${CLIENT_PUBLICPATH}
volumes:
# # 代表给当前容器和宿主机指定数据卷, 类似于docker run -v
- ./ot-system-client/nginx/templates:/etc/nginx/templates
- ./ot-system-client/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
# - admin:/usr/share/nginx/html # 绝对路径映射 映射多个数据卷 类似于docker run -v 注意:docker-compose使用绝对路劲要求必须先创建才能使用
# - ./data:/var/lib/mysql # 映射多个数据卷 类似于docker run -v 注意:docker-compose使用绝对路劲要求必须先创建才能使用
# envsubst 文档 https://www.baeldung.com/linux/envsubst-command
command:
- /bin/bash
- -c
- "envsubst '$$CLIENT_ADDRESS,$${CLIENT_PORT},$${CLIENT_SERVER_NAME},$${ADMIN_ADDRESS},$${ADMIN_PORT},$${ENTRY_PORT},$${ENTRY_SERVER_NAME},$${CLIENT_PUBLICPATH}' < /etc/nginx/templates/default.conf.template > /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'"
admin:
build:
context: ./ot-system-admin
args:
#将配置文件传入到 dockerfile 文件中
REDIS_ADDRESS: ${REDIS_ADDRESS} # redis ip
REDIS_PORT: ${REDIS_PORT} # redis 端口
MYSQL_ADDRESS: ${MYSQL_ADDRESS} # mysql ip
MYSQL_PORT: ${MYSQL_PORT} # mysql 端口
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} # mysql 密码
SERVER_ADDRESS: ${SERVER_ADDRESS} # serverip
SERVER_PORT: ${SERVER_PORT} # server 端口
CLIENT_ADDRESS: ${CLIENT_ADDRESS} # client ip
CLIENT_PORT: ${CLIENT_PORT} # client 端口
CLIENT_SERVER_NAME: ${CLIENT_SERVER_NAME}
CLIENT_PUBLICPATH: ${CLIENT_PUBLICPATH}
CLIENT_NODE_ENV: ${CLIENT_NODE_ENV} # CLIENT NODE_ENV
CLIENT_RENDER: ${CLIENT_RENDER}
ADMIN_ADDRESS: ${ADMIN_ADDRESS} # admin ip
ADMIN_PORT: ${ADMIN_PORT} # admin 端口
ADMIN_SERVER_NAME: ${ADMIN_SERVER_NAME}
ADMIN_PUBLICPATH: ${ADMIN_PUBLICPATH}
ADMIN_NODE_ENV: ${ADMIN_NODE_ENV} # ADMIN NODE_ENV
ADMIN_RENDER: ${ADMIN_RENDER}
ENTRY_ADDRESS: ${ENTRY_ADDRESS} # ENTRY ip
ENTRY_PORT: ${ENTRY_PORT} # ENTRY 端口
ENTRY_SERVER_NAME: ${ENTRY_SERVER_NAME}
dockerfile: Dockerfile
# image: nginx # 镜像名称
container_name: admin_container # 容器名字
restart: always # 开机自动重启
# env_file:
# - ot-system-admin/.env.production
ports:
- '${ADMIN_PORT}:${ADMIN_PORT}' # 主机端口:容器端口
expose:
- ${ADMIN_PORT} # 暴露出端口 给links使用
# environment:
# - ADMIN_PORT=${ADMIN_PORT}
# - NGINX_PORT=80
# - CLIENT=client
networks:
- app
# networks:
# app:
# #当前服务器使用哪个桥
# ipv4_address: 172.16.0.2 # 具体ip
# - ./nginx/nginx.conf:/etc/nginx/nginx.conf #配置文件
# - ./log:/var/log/nginx ###这里面放置日志
# - ./html:/html ###这里面放置项目目录
links:
- server # 网络连接到server中
depends_on:
- server
environment:
# 是环境变量
- CLIENT_ADDRESS=${CLIENT_ADDRESS} # client ip
- CLIENT_PORT=${CLIENT_PORT} # client 端口
- CLIENT_SERVER_NAME=${CLIENT_SERVER_NAME} # client SERVER
- ADMIN_ADDRESS=${ADMIN_ADDRESS} # admin ip
- ADMIN_PORT=${ADMIN_PORT} # admin 端口
- ADMIN_SERVER_NAME=${ADMIN_SERVER_NAME} # admin server
- ADMIN_PUBLICPATH=${ADMIN_PUBLICPATH}
- ADMIN_NODE_ENV=${ADMIN_NODE_ENV} # ADMIN NODE_ENV
- ADMIN_RENDER=${ADMIN_RENDER}
volumes:
# # 代表给当前容器和宿主机指定数据卷, 类似于docker run -v
- ./ot-system-admin/nginx/templates:/etc/nginx/templates
- ./ot-system-admin/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
# - admin:/usr/share/nginx/html # 绝对路径映射 映射多个数据卷 类似于docker run -v 注意:docker-compose使用绝对路劲要求必须先创建才能使用
# - ./data:/var/lib/mysql # 映射多个数据卷 类似于docker run -v 注意:docker-compose使用绝对路劲要求必须先创建才能使用
# envsubst 文档 https://www.baeldung.com/linux/envsubst-command
command:
- /bin/bash
- -c
- "envsubst '$$CLIENT_ADDRESS,$$CLIENT_PORT,$$CLIENT_SERVER_NAME,$$ADMIN_ADDRESS,$$ADMIN_PORT,$$ADMIN_SERVER_NAME,$$ENTRY_PORT,$$ENTRY_SERVER_NAME,$${ADMIN_PUBLICPATH}' < /etc/nginx/templates/default.conf.template > /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'"
entry:
build:
context: ./DockerFiles/nginx
args:
#将配置文件传入到 dockerfile 文件中
REDIS_ADDRESS: ${REDIS_ADDRESS} # redis ip
REDIS_PORT: ${REDIS_PORT} # redis 端口
MYSQL_ADDRESS: ${MYSQL_ADDRESS} # mysql ip
MYSQL_PORT: ${MYSQL_PORT} # mysql 端口
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} # mysql 密码
SERVER_ADDRESS: ${SERVER_ADDRESS} # serverip
SERVER_PORT: ${SERVER_PORT} # server 端口
CLIENT_ADDRESS: ${CLIENT_ADDRESS} # client ip
CLIENT_PORT: ${CLIENT_PORT} # client 端口
CLIENT_SERVER_NAME: ${CLIENT_SERVER_NAME}
CLIENT_PUBLICPATH: ${CLIENT_PUBLICPATH}
ADMIN_ADDRESS: ${ADMIN_ADDRESS} # admin ip
ADMIN_PORT: ${ADMIN_PORT} # admin 端口
ADMIN_SERVER_NAME: ${ADMIN_SERVER_NAME}
ADMIN_PUBLICPATH: ${ADMIN_PUBLICPATH}
ENTRY_ADDRESS: ${ENTRY_ADDRESS} # ENTRY ip
ENTRY_PORT: ${ENTRY_PORT} # ENTRY 端口
ENTRY_SERVER_NAME: ${ENTRY_SERVER_NAME}
dockerfile: Dockerfile
# args: #传递参数给buid
# - NGINX_HOST=${NGINX_HOST}
# image: nginx # 镜像名称
container_name: entry_container # 容器名字
restart: always # 开机自动重启
ports:
- '${ENTRY_PORT}:${ENTRY_PORT}' # 主机端口:容器端口
expose:
- ${ENTRY_PORT} # 暴露出端口 给links使用
networks:
- app
# networks:
# app:
# #当前服务器使用哪个桥
# ipv4_address: 172.16.0.2 # 具体ip
# - ./nginx/nginx.conf:/etc/nginx/nginx.conf #配置文件
# - ./log:/var/log/nginx ###这里面放置日志
# - ./html:/html ###这里面放置项目目录
# links:
# - client # 网络连接到client中
# - admin # 网络连接到admin中
depends_on:
- server
- client
- admin
# 优先构建redis 容器, 在构建 server容器
# command: "redis-server /usr/local/etc/redis/redis.conf" # 覆盖 Dockerfile 中的 cmd
# env_file:
# - .env
environment:
# 是环境变量
- CLIENT_ADDRESS=${CLIENT_ADDRESS} # client ip
- CLIENT_PORT=${CLIENT_PORT} # client 端口
- ADMIN_ADDRESS=${ADMIN_ADDRESS} # admin ip
- ADMIN_PORT=${ADMIN_PORT} # admin 端口
- ENTRY_PORT=${ENTRY_PORT} #nginx 端口号
- ENTRY_SERVER_NAME=${ENTRY_SERVER_NAME}
- SERVER_ADDRESS=${SERVER_ADDRESS} # serverip
- SERVER_PORT=${SERVER_PORT} # server 端口
volumes:
# # 代表给当前容器和宿主机指定数据卷, 类似于docker run -v
- ./DockerFiles/nginx/templates:/etc/nginx/templates
- ./DockerFiles/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
# - admin:/usr/share/nginx/html # 绝对路径映射 映射多个数据卷 类似于docker run -v 注意:docker-compose使用绝对路劲要求必须先创建才能使用
# - ./data:/var/lib/mysql # 映射多个数据卷 类似于docker run -v 注意:docker-compose使用绝对路劲要求必须先创建才能使用
# envsubst 文档 https://www.baeldung.com/linux/envsubst-command
command:
- /bin/bash
- -c
- "envsubst '$$CLIENT_ADDRESS,$${CLIENT_PORT},$${ADMIN_ADDRESS},$${ADMIN_PORT},$${ENTRY_PORT},$${ENTRY_SERVER_NAME},$${SERVER_ADDRESS},$${SERVER_PORT}' < /etc/nginx/templates/default.conf.template > /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'"
networks:
# 固定ip设置
# app:
# ipam:
# config:
# - subnet: 172.16.0.0/100
# ip_range: 172.28.5.0/24
#声明定义上面的网桥模式 默认创建的是bridge
# 动态ip设置
app:
driver: bridge
# 容器和宿主机宗卷
volumes:
client:
admin: