-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
207 lines (198 loc) · 5.4 KB
/
Copy pathdocker-compose.yml
File metadata and controls
207 lines (198 loc) · 5.4 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
services:
# MongoDB 服务
mongodb:
image: mongo:4.2.12
container_name: foodshop-mongodb
restart: always
env_file:
- .env
ports:
- "${MONGO_PORT:-28017}:28017"
command: mongod --port 28017
environment:
MONGO_INITDB_DATABASE: elm_db
MONGO_INITDB_ROOT_USERNAME: ${MONGO_INITDB_ROOT_USERNAME}
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD}
volumes:
- mongodb_data:/data/db
networks:
- foodshop-network
healthcheck:
test: ["CMD-SHELL", "mongo --port 28017 --quiet --username $$MONGO_INITDB_ROOT_USERNAME --password $$MONGO_INITDB_ROOT_PASSWORD --authenticationDatabase admin --eval 'db.runCommand(\"ping\").ok'"]
interval: 10s
timeout: 5s
retries: 5
start_period: 40s
# Redis 服务
redis:
image: redis:7-alpine
container_name: foodshop-redis
restart: always
environment:
- REDIS_PASSWORD=${REDIS_PASSWORD:-}
ports:
- "${REDIS_PORT:-6379}:6379"
command: ["sh", "-c", "if [ -n \"$$REDIS_PASSWORD\" ]; then redis-server --appendonly yes --requirepass $$REDIS_PASSWORD; else redis-server --appendonly yes; fi"]
volumes:
- redis_data:/data
networks:
- foodshop-network
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 5
# RabbitMQ 服务
rabbitmq:
image: rabbitmq:3.10.5-management-alpine
container_name: foodshop-rabbitmq
restart: always
env_file:
- .env
ports:
- "${RABBITMQ_PORT:-5672}:5672"
- "${RABBITMQ_MANAGEMENT_PORT:-15672}:15672"
environment:
RABBITMQ_DEFAULT_USER: ${RABBITMQ_DEFAULT_USER}
RABBITMQ_DEFAULT_PASS: ${RABBITMQ_DEFAULT_PASS}
volumes:
- rabbitmq_data:/var/lib/rabbitmq
networks:
- foodshop-network
healthcheck:
test: rabbitmq-diagnostics -q ping
interval: 10s
timeout: 5s
retries: 5
# 数据库初始化服务(一次性执行)
node-init:
image: ${DOCKER_USER}/foodshop-${PLATFORM_TAG:-amd64}
platform: ${PLATFORM:-linux/amd64}
container_name: foodshop-init
env_file:
- .env
environment:
- NODE_ENV=production
- MONGO_URL=${MONGO_URL}
depends_on:
mongodb:
condition: service_healthy
command: ["node", "scripts/init-db.js"]
networks:
- foodshop-network
restart: "no"
# Node.js 应用服务
node:
image: ${DOCKER_USER}/foodshop-${PLATFORM_TAG:-amd64}
platform: ${PLATFORM:-linux/amd64}
build:
context: .
dockerfile: Dockerfile
platforms:
- ${PLATFORM:-linux/amd64}
container_name: foodshop
restart: always
env_file:
- .env
ports:
- "${PORT:-3000}:3000"
environment:
- NODE_ENV=${NODE_ENV:-production}
- MONGO_URL=${MONGO_URL}
- REDIS_HOST=${REDIS_HOST:-redis}
- REDIS_PORT=6379
- REDIS_PASSWORD=${REDIS_PASSWORD:-}
- RABBITMQ_HOST=${RABBITMQ_HOST:-rabbitmq}
- RABBITMQ_PORT=${RABBITMQ_PORT:-5672}
- QINIU_BUCKET=${QINIU_BUCKET:-elm-dev}
- QINIU_ACCESS_KEY=${QINIU_ACCESS_KEY}
- QINIU_SECRET_KEY=${QINIU_SECRET_KEY}
volumes:
- ./logs:/app/logs
depends_on:
mongodb:
condition: service_healthy
redis:
condition: service_healthy
rabbitmq:
condition: service_healthy
node-init:
condition: service_completed_successfully
networks:
- foodshop-network
healthcheck:
test: ["CMD", "node", "-e", "require('http').get('http://127.0.0.1:3000/', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
# H5 前端应用
h5-app:
image: ${DOCKER_USER}/foodshop-h5-${PLATFORM_TAG:-amd64}
platform: ${PLATFORM:-linux/amd64}
build:
context: ../foodshop-h5
dockerfile: Dockerfile
platforms:
- ${PLATFORM:-linux/amd64}
container_name: foodshop-h5-app
restart: always
volumes:
- h5_dist:/usr/share/nginx/html/hi-user
networks:
- foodshop-network
# Admin 管理后台应用
admin-app:
image: ${DOCKER_USER}/foodshop-admin-${PLATFORM_TAG:-amd64}
platform: ${PLATFORM:-linux/amd64}
build:
context: ../foodshop-admin
dockerfile: Dockerfile
platforms:
- ${PLATFORM:-linux/amd64}
container_name: foodshop-admin-app
restart: always
volumes:
- admin_dist:/usr/share/nginx/html/admin-user
networks:
- foodshop-network
# Nginx 反向代理
nginx:
image: nginx:1.24-alpine
container_name: foodshop-nginx
restart: always
ports:
- "${NGINX_PORT:-80}:80"
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
- ./nginx/default.d:/etc/nginx/default.d:ro
- ./logs/nginx:/var/log/nginx
- h5_dist:/usr/share/nginx/html/hi-user:ro
- admin_dist:/usr/share/nginx/html/admin-user:ro
depends_on:
- node
- h5-app
- admin-app
networks:
- foodshop-network
healthcheck:
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://127.0.0.1/nginx-health"]
interval: 10s
timeout: 5s
retries: 3
networks:
foodshop-network:
driver: bridge
volumes:
mongodb_data:
driver: local
mongodb_config:
driver: local
redis_data:
driver: local
rabbitmq_data:
driver: local
h5_dist:
driver: local
admin_dist:
driver: local