docker run command. For example, to start an instance of a web server:
docker run, setting up load balancing, and monitoring each instance is simply not scalable.
Docker Swarm orchestration automates container management by running multiple instances of your service across a cluster of nodes.
Introducing Docker Swarm and Services
Docker Swarm provides orchestration that automatically manages and maintains multiple instances (tasks) of your service. The key component is the Docker service, which represents one or more containers running a single application across the Swarm Cluster. For instance, to create a service running multiple instances of your web server using the manager node, use:docker service create command, the manager node’s orchestrator determines the number of tasks (each corresponding to one container instance) to create. The scheduler then assigns these tasks to worker nodes, ensuring that if a container fails, the manager is notified and a new task is automatically rescheduled.
Service Distribution Scenarios
Consider these scenarios when deploying services in your cluster:- Limited Nodes: If you have only two worker nodes and request three replicas, Docker Swarm will distribute the three containers across the available nodes.
- Spare Capacity: With four worker nodes and a service defined with three replicas, three nodes run one container each, leaving one node idle. However, if one of the active nodes fails, Swarm will relaunch a container on an available node to maintain the desired replica count.
Types of Docker Services
Docker Swarm provides two primary types of services:1. Replicated Services
With replicated services, you define the desired number of container instances using the--replicas option, regardless of the number of available worker nodes. This is ideal for scalable applications such as web servers. For example:
2. Global Services
Global services run exactly one instance on every worker node. This model is perfect for use cases such as monitoring agents, log collectors, or antivirus scanners that need to operate on all nodes in your cluster. To deploy a monitoring agent across all nodes, run:If you do not specify a custom name, Docker swarms automatically generate a memorable name for your service. When you use the
--name option, Docker Swarm appends a unique number to each container’s name to ensure distinction within the cluster.