امنیت، هویت، استقرار و تاب‌آوری · فصل ۴ — Linux/Windows، Container، DNS، CDN و Storage · 97

Docker Compose: Dependencies, Health and Restart

Build a Compose service-dependency model that separates creation/start order, readiness via health conditions, one-shot completion and explicit dependency restart behavior, then verify failure and recovery with a deterministic local stack. می‌تواند برای «Docker Compose: Dependencies, Health و Restart» run/release model و signals/recovery checks لازم را برای یک سرویس محدود طراحی کند.

Docker Compose: Dependencies, Health و Restart — fa-IR

Lesson summary

Build a Compose service-dependency model that separates creation/start order, readiness via health conditions, one-shot completion and explicit dependency restart behavior, then verify failure and recovery with a deterministic local stack.

می‌تواند برای «Docker Compose: Dependencies, Health و Restart» run/release model و signals/recovery checks لازم را برای یک سرویس محدود طراحی کند.

This lesson produces

می‌تواند برای «Docker Compose: Dependencies, Health و Restart» run/release model و signals/recovery checks لازم را برای یک سرویس محدود طراحی کند.

Who it is for

Foundation

Worked runtime map, explicit evidence table, local fixture and one guided failure probe.

Repair

Reduce to one broken runtime/configuration assumption, observe it, repair it, then restore the full case.

Experienced

Compress introductory syntax; require independent diagnosis, negative evidence and bounded recovery decision.

Prerequisites

1. The problem: “the container started” does not mean “the service is ready”

In a multi-service stack, container creation/start order is only part of runtime truth. A dependency can be Running while its endpoint is not ready, a migration has not completed, or its healthcheck still fails. A dependency restart also does not automatically imply the dependent service restarts.

The owned artifact is Compose Dependency Health Restart Record v1. It keeps the dependency graph, satisfaction condition, health contract, start/readiness observations, one-shot completion, restart trigger, and recovery evidence separate.

2. The dependency graph first controls order

Compose uses declared dependency relations to control create/start and removal ordering. If web depends on db, the dependency is created and started before the dependent service.

That ordering is important evidence, but it is not readiness or business-correctness evidence. Record graph and startup order independently from health.

3. Short-form depends_on closes only the “started” boundary

With short syntax, dependency services are started before the dependent service, but Compose does not wait for them to become healthy. This distinction causes a common startup race: the process is running while the service cannot yet handle real requests.

One lab fixture has exactly that state: the dependency is Running but ready=false. The correct conclusion is START_ORDER_ONLY_NOT_READY, not “Compose is broken.”

4. Long-form conditions make the dependency contract explicit

Long-form depends_on can declare the satisfaction condition. The three conditions owned by this lesson are service_started, service_healthy, and service_completed_successfully.

Choose the condition from the dependency contract. A long-running service that must accept requests may need more than service_started; a one-shot initializer has a different completion contract from a daemon health contract.

5. service_healthy depends on a healthcheck

service_healthy is meaningful only when the dependency has a defined healthcheck and reaches the expected healthy state. Compose can delay dependent startup until that health condition passes.

A passing healthcheck proves only the probe that was defined. It does not prove every business requirement, data invariant, or downstream authorization.

6. A healthcheck needs an explainable contract

A useful healthcheck identifies what it probes, what it does not probe, and how interval, timeout, retries, and start period shape the observation.

The Record keeps the probe contract separate from the observed health state. Do not expand a narrow probe into a broader readiness or correctness claim.

7. service_completed_successfully is for a one-shot dependency

Some dependencies are not daemons. An initializer or migration job must run and exit successfully. service_completed_successfully therefore has semantics distinct from service_healthy.

The lab includes a one-shot initializer. If its completion result fails, the dependent cannot be considered ready merely because other long-running services are Running.

8. A failure probe must falsify a plausible shortcut

A stack can use short-form dependencies and happen to work on the first run. That happy path does not prove the configuration is correct. Strong evidence introduces a bounded failure.

The fixture deliberately delays dependency readiness. Start-only semantics expose the race; changing the declared condition to service_healthy must change the decisive evidence.

9. depends_on restart: true has a bounded meaning

Current Compose documentation defines dependency restart: true around an explicit Compose-controlled dependency update/restart, causing the dependent service to restart so it can re-establish its relationship.

Do not equate this with a container runtime automatically restarting a crashed dependency under its own restart policy. They are different triggers.

10. Runtime restart policy is a separate layer

Container restart policy controls what the runtime does when a container dies. It is independent from the dependency restart linkage expressed by Compose.

The lab contains one explicit Compose restart case and one runtime crash/restart case. The Record must show why their evidence and expected dependent behavior differ.

11. Shutdown order also follows the dependency graph

Compose also uses dependency order during teardown, removing dependent services before their dependencies. This is useful lifecycle evidence, but it does not replace application-level graceful shutdown design.

This lesson records only the bounded shutdown-order consequence of the dependency graph.

12. Applications still need dependency-failure resilience

Even a precise Compose model cannot guarantee that a dependency will never fail later. Retry, timeout, circuit breaking, and degraded-mode behavior remain application/architecture concerns; depends_on is not a substitute for them.

Keep residual risk and unknowns visible. Configuration success is not proof of full resilience.

13. Compose Dependency Health Restart Record v1

For each dependency, the artifact records the dependent → dependency edge, condition, health or one-shot contract, observed startup state, readiness state, failure injection, explicit restart trigger, runtime restart behavior, recovery observation, and residual assumption.

Keep direct observation, inference, and unknowns separate. If decisive evidence is missing, leave the claim OPEN.

14. Lab and transfer

The lab is fully offline and synthetic. Eight fixtures model event, health, completion, and restart facts for a small stack. No Docker registry, production service, credential, or external network is used.

The transfer case changes a non-hard dependency, the readiness signal, the initializer result, and the restart linkage. Recompute all eight states from the changed evidence rather than copying baseline conclusions.

15. Sources, freshness, and claim boundaries

On 2026-09-19 the official Docker documentation was rechecked: Compose still derives startup/shutdown order from dependencies; Running is distinct from Ready; long-form conditions include service_started, service_healthy, and service_completed_successfully; and dependency restart: true is distinct from automated runtime restart after container death.

These are tool-sensitive claims. The next review is due on 2026-10-17, with earlier requalification after material Compose-documentation or fixture changes.

Assessment

There is no answer key in this lesson pack; answer it yourself and mark honestly. "Needs review" sends the lesson to your review queue.

OPS-004-S1 retrieval

State the bounded Compose dependency model and one non-goal.

lesson ✗AI ✗notes ✗

OPS-004-S2 application

Complete Compose Dependency Health Restart Record v1 for a supplied synthetic dependency graph using only fixture evidence.

lesson ✗AI ✗notes ✗

OPS-004-S3 diagnosis

Diagnose a started-not-ready, failed-health, or failed-one-shot case without blaming an unchanged layer.

lesson ✗AI ✗notes ✗

OPS-004-S4 decision

Distinguish an explicit Compose dependency restart from an automated runtime crash restart and choose a bounded recovery check.

lesson ✗AI ✗notes ✗

OPS-004-S5 transfer

Rebuild the record for a changed dependency condition, readiness signal, completion result, and restart linkage without copying baseline conclusions.

lesson ✗AI ✗notes ✗
Assessment rubric

A sufficient submission must satisfy all critical dimensions:

  1. Dependency-model correctness — graph, startup order, condition, readiness, one-shot completion, and restart semantics remain distinct.
  2. Evidence quality — direct observations are traceable; inference and unknowns are labeled.
  3. Scope discipline — health is not business correctness; Compose ordering is not application resilience or universal orchestration.
  4. Recovery proof — the failed condition or restart distinction is re-observed after a bounded repair/change.
  5. Transfer independence — the changed-context case is recomputed from its own evidence.

Blocking failure occurs when Running is treated as Ready, explicit Compose restart is collapsed into runtime restart policy, or transfer copies a baseline verdict.

References & freshness

Docker Docs — Control startup and shutdown order in Compose
·
Docker Docs — Compose file reference: services / depends_on
·
MAKNOW instructional evidence design
·

Case studies

SIMPLE

A database becomes healthy before the web service starts; startup order and readiness evidence both close.

WRONG_APPROACH

Short-form depends_on starts the dependency but readiness remains false; treating Running as Ready is rejected.

EDGE_OR_FAILURE

A one-shot initializer exits non-zero, so service_completed_successfully remains unsatisfied even while long-running services are healthy.

TRANSFER_NEAR

A changed dependency condition, readiness signal, one-shot result, and restart linkage require a fresh operations record.

Lesson visuals

OPS004-V1

Lab files

Everything is local and synthetic. No Docker registry, production service, credential, host mutation, or external network request is used.

For each fixture produce eight states: dependency_graph_state, startup_order_state, dependency_condition_state, health_readiness_state, completion_gate_state, restart_semantics_state, evidence_boundary_state, and recovery_decision_state.

Rules:

  1. Dependency order is not readiness.
  2. service_started closes only the start condition.
  3. service_healthy is bounded to the declared healthcheck.
  4. service_completed_successfully is evaluated from one-shot completion evidence.
  5. Dependency restart: true applies to explicit Compose-controlled restart/update evidence, not arbitrary runtime crash restart.
  6. Application retry/resilience remains outside the Compose ordering conclusion.
  7. If decisive evidence is absent, leave the conclusion OPEN.
  8. The transfer fixture must be recomputed from its changed condition and restart linkage.

Run python -B run_checks.py for learner-visible structural checks. Hidden acceptance lives outside learner paths.

Lesson media & slides

MAKNOW_OPS-004_DECISION_EVIDENCE_TABLE_v1.0.0.svg
DECISION EVIDENCE TABLE v1.0.0.svg
MAKNOW_OPS-004_FAILURE_REPAIR_v1.0.0.svg
FAILURE REPAIR v1.0.0.svg
MAKNOW_OPS-004_PRIMARY_MODEL_v1.0.0.svg
PRIMARY MODEL v1.0.0.svg
MAKNOW_OPS-004_WORKED_EXAMPLE_v1.0.0.svg
WORKED EXAMPLE v1.0.0.svg

Teaching files (download)

XLSXCompose Dependency Health Restart Record v1 v1.0.0.xlsxTeaching files (download)
DOCXCompose Dependency Health Restart Record v1 WORKSHEET v1.0.0.docxTeaching files (download)
PDFCompose Dependency Health Restart Record v1 WORKSHEET v1.0.0.pdfTeaching files (download)