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
- Worker Nodes
- Services & Tasks
Manager nodes handle cluster management tasks:
- Maintaining cluster state
- Scheduling services
- Serving Swarm API endpoints
- Leader election using Raft consensus
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: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
- Replicated Mode (Default)
- Global Mode
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: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: 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:Promote/Demote Nodes
Remove a Node
Monitoring Swarm
Service Status
Node Health
Using Dokploy API
Best Practices
Use 3 or 5 Manager Nodes
Use 3 or 5 Manager Nodes
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)
Separate Manager and Worker Workloads
Separate Manager and Worker Workloads
In production, dedicate managers to orchestration:
Use Health Checks
Use Health Checks
Define health checks for automatic recovery:
Implement Resource Limits
Implement Resource Limits
Prevent resource exhaustion:
Use Overlay Networks with Encryption
Use Overlay Networks with Encryption
Enable encryption for sensitive data:
Troubleshooting
Service tasks failing to start
Service tasks failing to start
- Check service logs:
docker service logs service-name - Verify image exists and is accessible
- Check resource constraints are satisfiable
- Review placement constraints
Network connectivity issues
Network connectivity issues
- 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
Manager node not responding
Manager node not responding
- Check manager quorum:
docker node ls - Review manager logs:
journalctl -u docker - Verify Raft consensus is healthy
- Ensure sufficient manager nodes are available
Rolling update stuck
Rolling update stuck
- 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