0
0
Dockerdevops~10 mins

Manager and worker nodes in Docker - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Manager and worker nodes
Start Docker Swarm
Initialize Manager Node
Manager Node Creates Swarm
Worker Nodes Join Swarm
Manager Assigns Tasks
Worker Nodes Execute Tasks
Manager Monitors and Controls Swarm
End or Scale Swarm
This flow shows how a manager node initializes a swarm, worker nodes join it, and the manager assigns and monitors tasks.
Execution Sample
Docker
docker swarm init
# On manager node

docker swarm join --token <worker-token> <manager-ip>:2377
# On worker node
Initialize a manager node to create a swarm, then join worker nodes to the swarm using a token.
Process Table
StepActionNode TypeCommandResult
1Initialize swarmManagerdocker swarm initManager node becomes swarm leader
2Get join tokenManagerdocker swarm join-token workerDisplays token for workers
3Join swarmWorkerdocker swarm join --token <token> <manager-ip>:2377Worker node joins swarm
4Assign taskManagerdocker service create --name web nginxService created and tasks assigned
5Run taskWorkerRuns nginx container as taskWorker runs assigned container
6Monitor swarmManagerdocker node lsShows all nodes and their status
7Exit--All nodes active and tasks running
💡 Swarm is running with manager controlling and workers executing tasks
Status Tracker
VariableStartAfter Step 1After Step 3After Step 5Final
Swarm StateNot initializedActive (manager)Active (manager + worker)Active (manager + worker running tasks)Active (all nodes healthy)
Node RoleNoneManagerManager + WorkerManager + WorkerManager + Worker
Tasks Running0001 (nginx container)1 (nginx container)
Key Moments - 3 Insights
Why does the worker node need a token to join the swarm?
The token is a secret that the manager generates to securely allow only authorized workers to join. See execution_table step 2 and 3.
Can a worker node become a manager automatically?
No, a worker node joins with the worker role only. Manager nodes are initialized separately. See execution_table step 1 and 3.
What happens if the manager node goes down?
The swarm loses its control plane; tasks may continue but no new tasks or changes can be made until a manager is restored.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what command does the worker node run to join the swarm?
Adocker swarm init
Bdocker swarm join --token <token> <manager-ip>:2377
Cdocker node ls
Ddocker service create --name web nginx
💡 Hint
Check step 3 in the execution_table for the worker node join command.
At which step does the manager assign tasks to worker nodes?
AStep 4
BStep 2
CStep 5
DStep 6
💡 Hint
Look for the step where a service is created in the execution_table.
What is the swarm state after step 1?
ANot initialized
BActive (worker)
CActive (manager)
DInactive
💡 Hint
Check variable_tracker for Swarm State after step 1.
Concept Snapshot
Manager node initializes swarm with 'docker swarm init'.
Worker nodes join using a token from manager.
Manager assigns tasks via services.
Workers run tasks assigned.
Manager monitors nodes and controls swarm state.
Full Transcript
In Docker Swarm, the manager node starts the swarm using 'docker swarm init'. This makes it the leader. The manager generates a token that worker nodes use to join the swarm securely. Workers join with 'docker swarm join --token <token> <manager-ip>:2377'. Once joined, the manager can assign tasks by creating services, which workers run as containers. The manager monitors all nodes and manages the swarm's state. If the manager goes down, control is lost until it is restored.