We don't run containers on a Swarm cluster; rather, we deploy services. These are atomic workloads that can be deployed in a Docker Swarm cluster. Services are defined by tasks, and each task is represented by a container in the Docker Swarm model. Swarm is based on SwarmKit and its logic is inherited. SwarmKit was created as a response to clustering any kind of task (such as virtual machines, for example), but Docker Swarm works with containers.
The Docker Swarm orchestrator uses a declarative model. This means that we define the desired state for our services and Docker Swarm will take care of the rest. If the defined number of replicas or tasks for a service is wrong – for example, if one of them died – Docker Swarm will take action to recover the correct state of the service. In this example, it will deploy a new replica to keep all the required nodes healthy.
The following diagram represents services...