forked from Tfh-Yqf/erp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
86 lines (82 loc) · 2.19 KB
/
Copy pathdocker-compose.yml
File metadata and controls
86 lines (82 loc) · 2.19 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
version: '3'
services:
db:
image: mysql:8.0
restart: always
env_file:
- ./mysql/.env # 使用了环境变量文件
volumes:
- db_vol:/var/lib/mysql:rw # 挂载数据库数据, 可读可写
- ./mysql/my.cnf:/etc/mysql/my.cnf # 挂载配置文件
- ./mysql/init.sql:/docker-entrypoint-initdb.d/init.sql # 挂载数据初始化sql脚本
ports:
- "3307:3306"
networks:
- db_network
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
timeout: 20s
retries: 10
web:
build:
context: ./frontend/
volumes:
- ./frontend:/app
networks:
- db_network
- nginx_network
# 备份服务
backup:
image: alpine:latest # 使用更轻量的 alpine 镜像
restart: always
depends_on:
db:
condition: service_healthy
volumes:
- ./backups:/backups:rw
- ./scripts/backup.sh:/scripts/backup.sh:rw
- ./scripts/backup-entrypoint.sh:/backup-entrypoint.sh:rw
networks:
- db_network
# 创建独立的启动脚本
command: ["/bin/sh", "/backup-entrypoint.sh"]
env_file:
- ./mysql/.env # 使用相同的环境变量文件
backend:
build: ./django
restart: always
volumes:
- ./django:/app:rw
- ./uwsgi:/tmp
depends_on:
- db
networks:
- db_network
- nginx_network
ports:
- "8000:8000"
nginx:
build: ./nginx
ports:
- "8081:8080"
- "443:443"
expose:
- "80"
volumes:
- ./nginx/nginx.conf:/etc/nginx/conf.d/nginx.conf # 挂载nginx配置文件
- ./nginx/log:/var/log/nginx # 挂载日志
- ./frontend:/usr/share/nginx/html # 挂载静态文件
- ./django/media:/usr/share/nginx/html/media:ro # 挂载 Django 媒体文件(只读)
networks:
- nginx_network
depends_on:
- web
- backend
restart: always
networks: # 自定义网络(默认桥接), 不使用links通信
db_network:
driver: bridge
nginx_network:
driver: bridge
volumes: # 自定义数据卷
db_vol: #定义数据卷同步存放容器内mysql数据