Docker Swarm
Estimated reading: 4 minutes 294 views

Replicated and Global Modes in Docker Swarm: Explained

Introduction – Why Learn About Replicated and Global Modes?

In Docker Swarm, managing containerized applications efficiently across multiple nodes comes down to how you deploy your services. Docker offers two deployment modes — Replicated and Global — that serve different operational goals. Choosing the right mode ensures your services are scalable, resilient, and properly distributed across the cluster.

In this guide, you’ll learn:

  • The key differences between Replicated and Global modes
  • Real-world use cases for each
  • Example commands and behaviors
  • Tips for managing and switching between modes

What is Replicated Mode in Docker Swarm?

Replicated mode allows you to define the exact number of container instances (replicas) that should run for a service. Docker Swarm automatically schedules and distributes these replicas across the cluster.

Key Highlights:

  • You set the number of replicas using --replicas
  • Containers are distributed across available nodes
  • Ideal for scalable web apps, APIs, and backend services
  • Failed containers are automatically rescheduled to maintain availability

Example – Create a Replicated Service:

docker service create --name my_web --replicas 3 nginx

This deploys 3 Nginx containers across the swarm nodes under the service my_web.


What is Global Mode in Docker Swarm?

Global mode ensures that exactly one container runs on each eligible node in the Swarm cluster. It’s perfect for services that need to run cluster-wide, such as monitoring agents or log forwarders.

Key Highlights:

  • No replica count needed
  • Runs one task per node automatically
  • Ideal for node-level tools like logging, metrics, and sidecars
  • Automatically adjusts to node joins or leaves

Example – Create a Global Service:

docker service create --name myservice --mode global alpine top

This ensures one alpine container runs on every node in the cluster.


Comparison Table: Replicated Mode vs Global Mode

Feature Replicated Mode Global Mode
Replica CountUser-defined with --replicasOne per eligible node (auto-managed)
ScalingManual scaling via replica changesAuto-scales as nodes join/leave
Use CaseApp frontends, backends, workersMonitoring, logging, node-level apps
DeploymentScheduler distributes containersOne container per node
Node Failure BehaviorRedistributes to maintain countTask removed with the node
Command Flag--mode replicated --replicas N--mode global

When to Use Each Mode?

Use Replicated Mode When:

  • You want full control over how many instances run
  • You’re scaling stateless applications, like web or API services
  • You need load-balanced distribution of tasks

🟣 Use Global Mode When:

  • You need one instance per node (e.g., log shipper, health check agent)
  • You want services to automatically scale with node count
  • You’re deploying infrastructure-level components

Additional Notes

  • Both modes support placement constraints, allowing you to target services to specific nodes (e.g., only manager nodes or labeled nodes).
  • Docker Swarm’s control plane ensures the desired state is always maintained, automatically replacing failed tasks in both modes.
  • You can update a running service to switch between modes using: docker service update --mode global <service_name> docker service update --mode replicated --replicas 3 <service_name>

Summary – Recap & Key Takeaways

Docker Swarm’s Replicated and Global modes let you tailor service deployment to fit your application’s architecture and infrastructure needs. Whether you’re scaling microservices or distributing node-wide tools, choosing the right mode is essential.

Key Takeaways:

  • Use Replicated mode for scalable apps with specific replica counts.
  • Use Global mode for node-specific tools like log collectors.
  • You can update and switch modes dynamically using docker service update.
  • Both modes work seamlessly with Docker’s self-healing and scheduling logic.

Real-World Relevance: Mastering these modes enhances your ability to manage distributed applications reliably, especially in production environments with diverse workloads.


Frequently Asked Questions (FAQ)

Q1: What happens if I add a new node to a global service?

A new task is automatically created on that node without manual intervention.


Q2: Can I define replica count in global mode?

No. Global mode is designed to run one container per node, and it handles that automatically.


Q3: How does replicated mode handle failures?

If a container (task) fails, Swarm reschedules it on another node to maintain the desired replica count.


Q4: Which mode is best for monitoring agents like Prometheus exporters?

Global mode is ideal because you typically want one exporter per node to collect local metrics.


Q5: Can I change service mode after creation?

Yes. You can use docker service update to switch between replicated and global modes:

docker service update --mode global my_service

Call to Action – Try It Yourself!

Experiment with both modes in your own Swarm cluster:

Create a Replicated Service:

docker service create --name replicated_test --replicas 4 nginx

Create a Global Service:

docker service create --name global_test --mode global prom/node-exporter

Now:

  • Try scaling the replicated service
  • Add/remove nodes and watch the global service adapt
  • Use docker service ps to track task placement and behavior

Practice switching modes, monitor the results, and sharpen your container orchestration skills with real-time insights!


Share Now :
Share

Replicated and Global Modes in Docker Swarm

Or Copy Link

CONTENTS
Scroll to Top