forked from fastapi-practices/fastapi-best-architecture
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
241 lines (230 loc) · 6.57 KB
/
docker-compose.yml
File metadata and controls
241 lines (230 loc) · 6.57 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
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
networks:
fba_network:
name: fba_network
driver: bridge
ipam:
driver: default
config:
- subnet: 172.10.10.0/24
volumes:
# 如果你是 mysql 用户,应将 fba_postgres 修改为 fba_mysql
fba_postgres:
name: fba_postgres
fba_redis:
name: fba_redis
fba_static:
name: fba_static
fba_static_upload:
name: fba_static_upload
fba_rabbitmq:
name: fba_rabbitmq
services:
fba_server:
build:
context: .
dockerfile: Dockerfile
image: fba_server:latest
ports:
- "8001:8001"
container_name: fba_server
restart: always
# 如果你是 mysql 用户,应将 fba_postgres 修改为 fba_mysql
depends_on:
- fba_postgres
- fba_redis
volumes:
- ./deploy/backend/docker-compose/.env.server:/fba/backend/.env
- fba_static:/fba/backend/app/static
- fba_static_upload:/fba/backend/static/upload
networks:
- fba_network
# 如果你是 mysql 用户,应将 fba_postgres:5432 修改为 fba_mysql:3306
command:
- bash
- -c
- |
wait-for-it -s fba_postgres:5432 -s fba_redis:6379 -t 300
supervisord -c /etc/supervisor/supervisord.conf
supervisorctl restart
fba_postgres:
image: postgres:16
ports:
- "${DOCKER_POSTGRES_MAP_PORT:-5432}:5432"
container_name: fba_postgres
restart: always
environment:
POSTGRES_DB: fba
POSTGRES_PASSWORD: 123456
TZ: Asia/Shanghai
volumes:
- fba_postgres:/var/lib/postgresql/data
networks:
- fba_network
# # 如果你是 mysql 用户,应保留 fba_mysql 容器脚本并删除 fba_postgres 容器脚本
# fba_mysql:
# image: mysql:8.0.41
# ports:
# - "${DOCKER_MYSQL_MAP_PORT:-3306}:3306"
# container_name: fba_mysql
# restart: always
# environment:
# MYSQL_DATABASE: fba
# MYSQL_ROOT_PASSWORD: 123456
# TZ: Asia/Shanghai
# volumes:
# - fba_mysql:/var/lib/mysql
# networks:
# - fba_network
# command:
# --default-authentication-plugin=mysql_native_password
# --character-set-server=utf8mb4
# --collation-server=utf8mb4_general_ci
# --lower_case_table_names=1
fba_redis:
image: redis
ports:
- "${DOCKER_REDIS_MAP_PORT:-6379}:6379"
container_name: fba_redis
restart: always
environment:
- TZ=Asia/Shanghai
volumes:
- fba_redis:/data
networks:
- fba_network
# 【后端专用】
# 如果使用此容器,意味着你只需部署后端 API 服务,不需要前端
# 这与下面的 fba_ui 容器冲突,如果你选择使用 fba_ui 容器,你应该注释或删除 fba_nginx 容器脚本
fba_nginx:
image: nginx
ports:
- "8000:80"
container_name: fba_nginx
restart: always
depends_on:
- fba_server
volumes:
- ./deploy/backend/nginx.conf:/etc/nginx/conf.d/default.conf:ro
- fba_static:/www/fba_server/backend/static
- fba_static_upload:/www/fba_server/backend/static/upload
networks:
- fba_network
# # 如果服务器内存小于 4GB,CPU 小于四个内核
# # 建议通过前端工程单独构建此容器或在本地进行构建
# fba_ui:
# build:
# context: /root/fastapi_best_architecture_ui
# dockerfile: Dockerfile
# image: fba_ui:latest
# ports:
# - "80:80"
# - "443:443"
# container_name: fba_ui
# restart: always
# depends_on:
# - fba_server
# command:
# - nginx
# - -g
# - daemon off;
# volumes:
# # nginx https conf
# # 通过 docker 进行部署时,需要打开此配置项并确保<挂载到容器内的证书文件路径>配置
# # 与 nginx conf 中的 ssl 证书文件路径配置一致,如果你直接将 ssl 证书文件 cp
# # 到了 docker 容器内,则无需挂载证书文件,直接将它们注释或删除即可
# # local_ssl_pem_path:你在服务器存放 ssl pem 证书文件的路径,自行修改
# # local_ssl_key_path: 你在服务器存放 ssl key 证书文件的路径,自行修改
# # /etc/ssl/xxx.pem:挂载到容器内 ssl pem 证书文件的路径,自行修改
# # /etc/ssl/xxx.key:挂载到容器内 ssl key 证书文件的路径,自行修改
# - local_ssl_pem_path:/etc/ssl/xxx.pem
# - local_ssl_key_path:/etc/ssl/xxx.key
# - fba_static:/www/fba_server/backend/static
# - fba_static_upload:/www/fba_server/backend/static/upload
# networks:
# - fba_network
fba_rabbitmq:
hostname: fba_rabbitmq
image: rabbitmq:3.13.7
ports:
- "15672:15672"
- "5672:5672"
container_name: fba_rabbitmq
restart: always
environment:
- RABBITMQ_DEFAULT_USER=guest
- RABBITMQ_DEFAULT_PASS=guest
volumes:
- fba_rabbitmq:/var/lib/rabbitmq
networks:
- fba_network
fba_celery_worker:
build:
context: .
dockerfile: Dockerfile
args:
- SERVER_TYPE=fba_celery_worker
image: fba_celery_worker:latest
# 如果你需要分布式部署 Worker,则必须移除此 container_name 配置
container_name: fba_celery_worker
restart: always
depends_on:
- fba_rabbitmq
volumes:
- ./deploy/backend/docker-compose/.env.server:/fba/backend/.env
networks:
- fba_network
command:
- bash
- -c
- |
wait-for-it -s fba_rabbitmq:5672 -t 300
supervisord -c /etc/supervisor/supervisord.conf
supervisorctl restart
fba_celery_beat:
build:
context: .
dockerfile: Dockerfile
args:
- SERVER_TYPE=fba_celery_beat
image: fba_celery_beat:latest
container_name: fba_celery_beat
restart: always
depends_on:
- fba_rabbitmq
- fba_celery_worker
volumes:
- ./deploy/backend/docker-compose/.env.server:/fba/backend/.env
networks:
- fba_network
command:
- bash
- -c
- |
wait-for-it -s fba_rabbitmq:5672 -t 300
supervisord -c /etc/supervisor/supervisord.conf
supervisorctl restart
fba_celery_flower:
build:
context: .
dockerfile: Dockerfile
args:
- SERVER_TYPE=fba_celery_flower
image: fba_celery_flower:latest
ports:
- "8555:8555"
container_name: fba_celery_flower
restart: always
depends_on:
- fba_rabbitmq
- fba_celery_worker
volumes:
- ./deploy/backend/docker-compose/.env.server:/fba/backend/.env
networks:
- fba_network
command:
- bash
- -c
- |
wait-for-it -s fba_rabbitmq:5672 -t 300
supervisord -c /etc/supervisor/supervisord.conf
supervisorctl restart