mirror of
https://github.com/yeasy/docker_practice.git
synced 2026-08-10 16:37:34 +00:00
Document depends_on condition and healthcheck
This commit is contained in:
@@ -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`
|
||||
|
||||
|
||||
Reference in New Issue
Block a user