From a25bd76d17467c03b7e5cbe34e368ae7afa35b82 Mon Sep 17 00:00:00 2001 From: Allie Sadler <102604716+aevesdocker@users.noreply.github.com> Date: Thu, 4 Jul 2024 16:20:30 +0100 Subject: [PATCH] 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> --- content/compose/startup-order.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/content/compose/startup-order.md b/content/compose/startup-order.md index 03d88e4229..582dc7aa6a 100644 --- a/content/compose/startup-order.md +++ b/content/compose/startup-order.md @@ -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_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 - [`depends_on`](compose-file/05-services.md#depends_on)