mirror of https://github.com/docker/docs.git
ENGDOCS-2143 (#20301)
* ENGDOCS-2143 * Apply suggestions from code review Co-authored-by: Guillaume Lours <705411+glours@users.noreply.github.com> --------- Co-authored-by: Guillaume Lours <705411+glours@users.noreply.github.com>
This commit is contained in:
parent
55ab51303e
commit
a25bd76d17
|
|
@ -22,6 +22,38 @@ The solution for detecting the ready state of a service is to use the `conditio
|
||||||
- `service_healthy`. This specifies that a dependency is expected to be “healthy”, which is defined with `healthcheck`, before starting a dependent service.
|
- `service_healthy`. This specifies that a dependency is expected to be “healthy”, which is defined with `healthcheck`, before starting a dependent service.
|
||||||
- `service_completed_successfully`. This specifies that a dependency is expected to run to successful completion before starting a dependent service.
|
- `service_completed_successfully`. This specifies that a dependency is expected to run to successful completion before starting a dependent service.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
services:
|
||||||
|
web:
|
||||||
|
build: .
|
||||||
|
depends_on:
|
||||||
|
db:
|
||||||
|
condition: service_healthy
|
||||||
|
restart: true
|
||||||
|
redis:
|
||||||
|
condition: service_started
|
||||||
|
redis:
|
||||||
|
image: redis
|
||||||
|
db:
|
||||||
|
image: postgres
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}'"]
|
||||||
|
interval: 10s
|
||||||
|
retries: 5
|
||||||
|
start_period: 30s
|
||||||
|
timeout: 10s
|
||||||
|
```
|
||||||
|
|
||||||
|
Compose creates services in dependency order. `db` and `redis` are created before `web`.
|
||||||
|
|
||||||
|
Compose waits for healthchecks to pass on dependencies marked with `service_healthy`. `db` is expected to be "healthy" (as indicated by `healthcheck`) before `web` is created.
|
||||||
|
|
||||||
|
The healthcheck for the `db` service uses the `pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}'` command to check if the PostgreSQL database is ready. The service is retried every 10 seconds, up to 5 times.
|
||||||
|
|
||||||
|
Compose also removes services in dependency order. `web` is removed before `db` and `redis`.
|
||||||
|
|
||||||
## Reference information
|
## Reference information
|
||||||
|
|
||||||
- [`depends_on`](compose-file/05-services.md#depends_on)
|
- [`depends_on`](compose-file/05-services.md#depends_on)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue