Swarm task states
Docker lets you create services, which can start tasks. A service is a description of a desired state, and a task does the work. Work is scheduled on swarm nodes in this sequence:
- Create a service by using
docker service create.
- The request goes to a Docker manager node.
- The Docker manager node schedules the service to run on particular nodes.
- Each service can start multiple tasks.
- Each task has a life cycle, with states like
Tasks are execution units that run once to completion. When a task stops, it isn't executed again, but a new task may take its place.
Tasks advance through a number of states until they complete or fail. Tasks are
initialized in the
NEW state. The task progresses forward through a number of
states, and its state doesn't go backward. For example, a task never goes from
Tasks go through the states in the following order:
|The task was initialized.|
|Resources for the task were allocated.|
|Docker assigned the task to nodes.|
|The task was accepted by a worker node. If a worker node rejects the task, the state changes to |
|The worker node is ready to start the task|
|Docker is preparing the task.|
|Docker is starting the task.|
|The task is executing.|
|The task exited without an error code.|
|The task exited with an error code.|
|Docker requested the task to shut down.|
|The worker node rejected the task.|
|The node was down for too long.|
|The task is not terminal but the associated service was removed or scaled down.|
docker service ps <service-name> to get the state of a task. The
CURRENT STATE field shows the task's state and how long it's been
$ docker service ps webserver ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS owsz0yp6z375 webserver.1 nginx UbuntuVM Running Running 44 seconds ago j91iahr8s74p \_ webserver.1 nginx UbuntuVM Shutdown Failed 50 seconds ago "No such container: webserver.…" 7dyaszg13mw2 \_ webserver.1 nginx UbuntuVM Shutdown Failed 5 hours ago "No such container: webserver.…"