Docker Swarm¶
Docker Swarm cluster¶
- Manager Nodes (atleast one in cluster)
- Worker Node
Features of swarm¶
- Simplified setup
- Declarative
- Scaling
- Rolling Updates
- Self-Healing
- Security
- Load Balancing
- Service Discovery (Unique DNS names)
Setup Docker Swarm¶
Step 1:
Deploy Machines (VM or Physical)¶
Identify if swarm is active or not
:::info If swarm is setup it shows active :::
Open Ports on Docker swarm nodes¶
| Ports | Transport Layer Protocol | Usage |
|---|---|---|
| 2377 | TCP | Cluster Management Communications |
| 7946 | TCP and UDP | Communication among nodes |
| 4789 | UDP | Overlay network traffic |
Initialize swarm cluster¶
:::info This will provide command to connect worker nodes :::
Check if swarm is active
Add nodes to cluster¶
Get command to join cluster
List docker nodes¶
Inspect node¶
Activate or Drain nodes in Docker Swarm cluster¶
To drain a node
To activate node again
Remove node from cluster¶
Promote worker to manager¶
Demote worker from manager¶
Locking Docker Swarm nodes¶
Unlock docker swarm node¶
:::info provide the key :::
Run services on docker swarm nodes¶
This command calls → API → Orchestrator → Allocator → Dispatcher → Scheduler → Worker Nodes
Managing Services¶
List Services¶
List container in the service¶
Details of Service¶
Check Logs of service¶
Delete Service¶
Rolling Updates¶
Deploy App¶
:::info If replica is not specified, default is considered 1 :::
Add containers in service (Scale Up)¶
Remove containers from service (Scale down)¶
Update service (Rolling Update)¶
:::info In rolling updates One container is updated first then next, one by one
- To add delay between updating containers
--update-delay 60s - To update multiple containers at a time
--update-parallelism 3, update 3 replica at a time -
If update failed on any container/s then
:::--update-failure-action pause|continue|rollback¶
Downgrade the service (Roll Back)¶
Types of service¶
- Replicated service (1 if not specified)
- Global Service (One node on all nodes of the cluster)