Services and tasks

A service is a desired state (an image, a number of replicas, constraints); the managers turn it into tasks, one container each, placed on the nodes that can run them, and replace any task that ends.

How it works

docker service ps shows each slot with its history: New, Pending, Assigned, Preparing (pulling), Starting, Running, then Failed, Rejected, Shutdown or Orphaned. The scheduler spreads replicas over the eligible nodes. When a service is created, the manager resolves the image tag to a digest in the registry, so every node pulls the same image.

What breaks

A task Rejected with No such image ran on a node that cannot get the image: it was only built locally, or the registry is unreachable. After five failures on a node within five minutes, Swarm avoids that node for the service, so replicas pile up on the one node that works and the service looks healthy until that node goes away.

In a terminal

docker service ls
docker service ps --no-trunc shop_api
docker service logs --tail 20 shop_api
docker service inspect --pretty shop_api

See it break, then fix it

Write the Dockerfile or the compose file, type the docker commands, and watch a simulated server run them through reboots, upgrades and traffic. Free to start.