| 短语法 | depends_on: [db](仅启动顺序) |
|---|---|
| 长语法 | condition: service_started / service_healthy / service_completed_successfully |
| 关键点 | 就绪等待必须有 healthcheck |
示例
示例
services:
api:
image: app/api:1.4.2
depends_on:
db:
condition: service_healthy
migrate:
condition: service_completed_successfully
db:
image: postgres:16-alpine
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
retries: 10condition 是 compose 在本地启停时的真实等待能力;容器内应用仍建议带连接重试,覆盖依赖中途重启的情况。