Document depends_on condition and healthcheck

This commit is contained in:
yeasy
2026-04-25 21:03:39 +00:00
parent 420a5776ce
commit 84a801f3ac
+37 -1
View File
@@ -132,7 +132,43 @@ services:
db:
image: postgres
```
> 注意`web` 服务不会等待 `redis` `db` 完全启动 之后才启动
> 注意上述简写形式中`web` 服务不会等待 `redis` `db` 完全启动 之后才启动
如果需要等待依赖服务就绪可以使用 `condition` 字段配合 `healthcheck`
```yaml
services:
web:
build: .
depends_on:
db:
condition: service_healthy
redis:
condition: service_healthy
redis:
image: redis
healthcheck:
test: [“CMD”, “redis-cli”, “ping”]
interval: 5s
timeout: 3s
retries: 5
db:
image: postgres
healthcheck:
test: [“CMD-SHELL”, “pg_isready -U postgres”]
interval: 5s
timeout: 3s
retries: 5
```
`condition` 支持三个值
* `service_started`容器启动即满足默认
* `service_healthy`容器的 `healthcheck` 状态为 healthy 时满足
* `service_completed_successfully`容器成功退出退出码为 0时满足适用于初始化任务等一次性容器
### 11.5.10 `dns`