mirror of
https://github.com/yeasy/docker_practice.git
synced 2026-08-10 16:37:34 +00:00
Add healthcheck to Rails Compose example
This commit is contained in:
@@ -106,6 +106,11 @@ services:
|
|||||||
POSTGRES_PASSWORD: password
|
POSTGRES_PASSWORD: password
|
||||||
volumes:
|
volumes:
|
||||||
- postgres_data:/var/lib/postgresql/data
|
- postgres_data:/var/lib/postgresql/data
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "pg_isready -U postgres"]
|
||||||
|
interval: 5s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 5
|
||||||
|
|
||||||
web:
|
web:
|
||||||
build: .
|
build: .
|
||||||
@@ -115,7 +120,8 @@ services:
|
|||||||
ports:
|
ports:
|
||||||
- "3000:3000"
|
- "3000:3000"
|
||||||
depends_on:
|
depends_on:
|
||||||
- db
|
db:
|
||||||
|
condition: service_healthy
|
||||||
environment:
|
environment:
|
||||||
DATABASE_URL: postgres://postgres:password@db:5432/myapp_development
|
DATABASE_URL: postgres://postgres:password@db:5432/myapp_development
|
||||||
|
|
||||||
@@ -128,7 +134,7 @@ volumes:
|
|||||||
|--------|------|
|
|--------|------|
|
||||||
| `rm -f tmp/pids/server.pid` | 清理上次异常退出留下的 PID 文件 |
|
| `rm -f tmp/pids/server.pid` | 清理上次异常退出留下的 PID 文件 |
|
||||||
| `volumes: .:/myapp` | 挂载代码目录,支持热更新 |
|
| `volumes: .:/myapp` | 挂载代码目录,支持热更新 |
|
||||||
| `depends_on: db` | 确保数据库先启动 |
|
| `depends_on` + `condition` | 等待数据库健康检查通过后再启动 |
|
||||||
| `DATABASE_URL` | Rails 12-factor 风格的数据库配置 |
|
| `DATABASE_URL` | Rails 12-factor 风格的数据库配置 |
|
||||||
|
|
||||||
### 11.7.6 步骤 4:生成 Rails 项目
|
### 11.7.6 步骤 4:生成 Rails 项目
|
||||||
|
|||||||
Reference in New Issue
Block a user