Skip to main content
In Docker Swarm, services define how containers are deployed and managed across a cluster. Swarm supports two primary service modes: replicated and global. This guide explains each mode, shows how to deploy them, and compares their use cases.

Replicated Service

A replicated service launches a specified number of identical tasks (containers). This is the default mode in Swarm.
If you omit --replicas, Swarm defaults to 1 replica. You can also explicitly set --mode replicated if you prefer.
To deploy five replicas of a web service:
docker service create \
  --name web \
  --replicas 5 \
  nginx:latest
Verify the service mode and replica count:
docker service inspect web \
  --format '{{json .Spec.Mode}}'
Sample output:
{"Replicated":{"Replicas":5}}
Key points for replicated services:
  • Tasks are spread evenly across available nodes.
  • Scale up or down by updating --replicas.
  • Ideal for stateless applications like web servers or APIs.

Global Service

A global service ensures exactly one task runs on every node in the Swarm.
Do not specify --replicas with global services. Use only --mode global.
To deploy a monitoring agent on all nodes:
docker service create \
  --name agent \
  --mode global \
  my-monitoring-agent:1.0
Global mode behavior:
  • New nodes automatically receive one task.
  • When a node leaves, its task is removed and not rescheduled.
  • Perfect for logging, monitoring, and security daemons.

Comparison Table

Service TypeReplica CountScheduling BehaviorCommon Use Case
ReplicatedUser-defined (N)Distributes tasks evenlyScalable web apps, microservices
GlobalOne per nodeRuns exactly one task on each nodeAgents for logging, monitoring

References