Add healthcheck to Rails Compose example

This commit is contained in:
yeasy
2026-05-03 05:23:12 +00:00
parent 625d209fa8
commit 10381deee4
+8 -2
View File
@@ -106,6 +106,11 @@ services:
POSTGRES_PASSWORD: password
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s
retries: 5
web:
build: .
@@ -115,7 +120,8 @@ services:
ports:
- "3000:3000"
depends_on:
- db
db:
condition: service_healthy
environment:
DATABASE_URL: postgres://postgres:password@db:5432/myapp_development
@@ -128,7 +134,7 @@ volumes:
|--------|------|
| `rm -f tmp/pids/server.pid` | 清理上次异常退出留下的 PID 文件 |
| `volumes: .:/myapp` | 挂载代码目录支持热更新 |
| `depends_on: db` | 确保数据库启动 |
| `depends_on` + `condition` | 等待数据库健康检查通过后再启动 |
| `DATABASE_URL` | Rails 12-factor 风格的数据库配置 |
### 11.7.6 步骤 4生成 Rails 项目