Services, tasks and desired state
Worked example
This is an offline lesson. Data are fictional and Docker commands are unexecuted. Any optional execution requires an authorized disposable VM, a verified context, synthetic data, restricted access and no external transmission. Do not collect secrets or private output. Use only the fictional worksheet for this exercise. Before a separately authorized read-only server query, verify the effective endpoint including environment overrides, project or cluster identity, and access scope. Never deploy the fragments, use real credentials or transmit private inspection output.
Synthetic service history:service: bm28_web; mode: replicated; desired: 3observed: 2 running, 1 failedmanager schedules replacement task if eligible capacity existsold task history remains; new task has a new identityStaged read-only inspection:docker service lsdocker service ps bm28_webThe service records the image, command, replica count, resources and update policy. Each scheduled task follows a lifecycle; a failed task is replaced according to policy rather than moved as a live container to another node. Task history can include stopped or rejected entries, so count current running tasks separately. A replicated service seeks a requested number of tasks; a global service seeks one task per eligible available node. A service can remain below desired replicas if images cannot be fetched, resources are insufficient or placement constraints exclude nodes. Inspect task status and sanitized errors before changing the service. Running replicas are not evidence of application readiness or data correctness. Task history can contain multiple generations for a single replica slot. Count currently active tasks and compare their desired/current state; do not count historical failures as additional desired replicas. Running is not independent business acceptance.
Common mistake
Never repair a managed service by manually replacing its task container with an unrelated standalone container. Diagnose the service specification and task history.
Manual practice
For desired count 4 and 2 running tasks, describe the missing capacity and two reasons replacement may remain pending. Compare a global service on three eligible nodes with a replicated service requesting five tasks.
Worksheet: lab-fixtures/docker-swarm-orchestration/02-desired-state/scenario.txt.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Services, tasks and desired state — Knowledge check
Interpret cluster orchestration evidence and make a safe operational decision.
What does a service specify?
What normally happens to a failed task under a suitable restart policy?
How many tasks does a global service seek on three eligible available nodes?