Skip to main content

Overview

Docker Swarm is Docker’s native clustering and orchestration tool that turns a pool of Docker hosts into a single virtual host. Dokploy leverages Docker Swarm to provide multi-node deployments, service scaling, load balancing, and high availability.
Docker Swarm is included with Docker Engine and requires no additional installation.

What is Docker Swarm?

Docker Swarm provides:
  • Cluster Management: Manage multiple Docker hosts as a single cluster
  • Service Discovery: Built-in DNS-based service discovery
  • Load Balancing: Automatic load balancing across containers
  • Scaling: Horizontal scaling of services
  • Rolling Updates: Zero-downtime deployments
  • Security: TLS authentication and encrypted communication

Swarm Architecture

Manager nodes handle cluster management tasks:
  • Maintaining cluster state
  • Scheduling services
  • Serving Swarm API endpoints
  • Leader election using Raft consensus
Recommendation: Use 3 or 5 manager nodes for high availability

Initializing Docker Swarm

Dokploy automatically initializes Docker Swarm during installation. You can verify the status:
Check Swarm Status

Manual Initialization

If you need to initialize Swarm manually:
1

Initialize on Manager Node

This returns a join token for worker nodes.
2

Add Worker Nodes

On each worker node, run:
3

Verify Cluster

Using the Cluster Router

Dokploy provides a Cluster API for managing Swarm:
Get Cluster Status
Initialize Cluster

Deploying Services to Swarm

Using Docker Compose with Swarm

Dokploy supports Docker Compose with Swarm-specific configuration:
docker-compose.yml

Deploy Modes

Runs a specified number of replicas across available nodes:

Service Scaling

Placement Constraints

Control where services run using constraints:

Node Attributes

Node Labels

Add custom labels to nodes:
Use labels in placement:

Update Strategies

Configure zero-downtime rolling updates:

Rollback Configuration

Service Discovery and Load Balancing

Internal Load Balancing

Swarm provides DNS-based service discovery:

Ingress Load Balancing

Swarm’s routing mesh distributes external traffic:
  • Requests to any node on the published port reach a service replica
  • Automatic load balancing across healthy replicas
  • No additional load balancer required

Overlay Networks

Create encrypted overlay networks for multi-node communication:

Network Isolation

Each service can use multiple networks:

Secrets Management

Swarm provides secure secret storage:
1

Create a Secret

2

Use in Service

Secrets are:
  • Encrypted at rest and in transit
  • Only available to services that explicitly request them
  • Mounted as files in /run/secrets/

Node Management

Drain a Node

Prepare a node for maintenance:
This stops scheduling new tasks and migrates existing tasks to other nodes.

Promote/Demote Nodes

Remove a Node

1

Drain the Node

2

Leave Swarm (on the node)

3

Remove from Cluster

Monitoring Swarm

Service Status

Node Health

Using Dokploy API

Best Practices

Raft consensus requires a quorum. Odd numbers provide fault tolerance:
  • 3 managers: tolerates 1 failure
  • 5 managers: tolerates 2 failures
  • 7+ managers: not recommended (increased overhead)
In production, dedicate managers to orchestration:
Define health checks for automatic recovery:
Prevent resource exhaustion:
Enable encryption for sensitive data:

Troubleshooting

  • Check service logs: docker service logs service-name
  • Verify image exists and is accessible
  • Check resource constraints are satisfiable
  • Review placement constraints
  • Verify overlay network is created: docker network ls
  • Check firewall rules (ports 2377, 7946, 4789)
  • Ensure nodes can communicate
  • Review network driver: docker network inspect network-name
  • Check manager quorum: docker node ls
  • Review manager logs: journalctl -u docker
  • Verify Raft consensus is healthy
  • Ensure sufficient manager nodes are available
  • Check service logs for errors
  • Review update configuration
  • Verify health checks are passing
  • Consider manual rollback: docker service rollback service-name

Next Steps

Multi-Node Deployment

Learn to deploy across multiple servers

Networking

Configure advanced networking

Volumes & Storage

Manage persistent storage in Swarm

Monitoring

Monitor your Swarm cluster