-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
64 lines (61 loc) · 2.93 KB
/
Copy pathdocker-compose.yml
File metadata and controls
64 lines (61 loc) · 2.93 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
services:
# ── Next.js 应用 ──────────────────────────────────────────────────────────
app:
build:
context: .
dockerfile: Dockerfile
ports:
- "9421:3000" # 宿主机 9421 → 容器内 3000
env_file:
- .env.docker # Docker 部署专用环境变量
environment:
- NODE_ENV=production
depends_on:
postgres:
condition: service_healthy # 等待 postgres 健康检查通过后再启动
redis:
condition: service_healthy # 等待 redis 健康检查通过后再启动
healthcheck:
test: ["CMD-SHELL", "wget -qO- http://localhost:3000/ || exit 1"]
interval: 15s
timeout: 5s
retries: 5
start_period: 30s
restart: unless-stopped
# ── PostgreSQL 数据库 ─────────────────────────────────────────────────────
postgres:
image: postgres:16-alpine
environment:
POSTGRES_USER: ${POSTGRES_USER:-timeline} # 默认用户名 timeline
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-timeline_pass} # 默认密码,生产环境请通过环境变量覆盖
POSTGRES_DB: ${POSTGRES_DB:-timeline} # 默认数据库名 timeline
volumes:
- postgres_data:/var/lib/postgresql/data # 持久化数据目录
- ./db:/docker-entrypoint-initdb.d # 首次启动时自动执行 db/ 下的 SQL 文件(按文件名排序)
ports:
- "5432:5432" # 暴露端口,便于本地工具连接;生产环境可移除
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-timeline} -d ${POSTGRES_DB:-timeline}"]
interval: 5s
timeout: 5s
retries: 10
restart: unless-stopped
# ── Redis 缓存 ────────────────────────────────────────────────────────────
redis:
image: redis:7-alpine
# 启用密码认证 + AOF 持久化(appendonly yes 防止重启后数据丢失)
command: redis-server --requirepass ${REDIS_PASSWORD:-redis_pass} --appendonly yes
volumes:
- redis_data:/data # 持久化 AOF/RDB 文件
ports:
- "6379:6379" # 暴露端口,便于本地调试;生产环境可移除
healthcheck:
test: ["CMD", "redis-cli", "-a", "${REDIS_PASSWORD:-redis_pass}", "ping"]
interval: 5s
timeout: 5s
retries: 10
restart: unless-stopped
# ── 命名卷 ────────────────────────────────────────────────────────────────
volumes:
postgres_data: # PostgreSQL 数据持久化
redis_data: # Redis 数据持久化