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:
Allie Sadler 2024-07-04 16:20:30 +01:00 committed by GitHub
parent 55ab51303e
commit a25bd76d17
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 32 additions and 0 deletions

View File

@ -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)