Bird
Raised Fist0
Dockerdevops~10 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What is the main role of a manager node in a Docker swarm?
easy
A. To monitor network traffic between containers
B. To run the containers and execute tasks
C. To control the swarm and assign tasks to worker nodes
D. To store container images locally

Solution

  1. Step 1: Understand the role of manager nodes

    Manager nodes control the swarm and decide which tasks run where.
  2. Step 2: Compare with worker nodes

    Worker nodes only run tasks assigned by managers, they don't control the swarm.
  3. Final Answer:

    To control the swarm and assign tasks to worker nodes -> Option C
  4. Quick Check:

    Manager node role = control and assign tasks [OK]
Hint: Managers control, workers execute tasks [OK]
Common Mistakes:
  • Confusing worker nodes as controllers
  • Thinking managers run containers directly
  • Assuming managers store images only
  • Mixing network monitoring with node roles
2. Which of the following commands correctly initializes a Docker swarm as a manager node?
easy
A. docker node create manager
B. docker swarm init
C. docker swarm start manager
D. docker node init

Solution

  1. Step 1: Recall the command to start a swarm

    The command docker swarm init initializes the current node as a manager.
  2. Step 2: Check other options for correctness

    Other commands like docker node create or docker swarm start do not exist or are invalid.
  3. Final Answer:

    docker swarm init -> Option B
  4. Quick Check:

    Initialize swarm = docker swarm init [OK]
Hint: Use 'docker swarm init' to start manager node [OK]
Common Mistakes:
  • Using non-existent commands
  • Confusing node creation with swarm init
  • Trying 'docker node init' which is invalid
  • Assuming 'docker swarm start' works
3. Given the following commands run on a new machine:
docker swarm init
docker node ls

What will be the output of docker node ls?
medium
A. A list showing one manager node with status 'Ready' and availability 'Active'
B. An error saying no nodes found
C. A list showing one worker node with status 'Down'
D. Empty output with no nodes listed

Solution

  1. Step 1: Understand 'docker swarm init' effect

    This command makes the current machine a manager node in the swarm.
  2. Step 2: Check 'docker node ls' output

    It lists all nodes in the swarm. Since only one node exists (the manager), it shows that node as 'Ready' and 'Active'.
  3. Final Answer:

    A list showing one manager node with status 'Ready' and availability 'Active' -> Option A
  4. Quick Check:

    One manager node listed after init = A list showing one manager node with status 'Ready' and availability 'Active' [OK]
Hint: After init, node list shows one active manager [OK]
Common Mistakes:
  • Expecting worker nodes without joining
  • Thinking output is empty or error
  • Confusing node status terms
  • Assuming node is down immediately
4. You ran docker swarm join --token SWMTKN-1-xyz 192.168.1.10:2377 on a node but it failed with "Error response from daemon: This node is already part of a swarm." What is the likely cause?
medium
A. The node is already a member of another swarm
B. The token is invalid or expired
C. The manager IP address is incorrect
D. Docker daemon is not running on the node

Solution

  1. Step 1: Analyze the error message

    The error says the node is already part of a swarm, so it cannot join another without leaving first.
  2. Step 2: Check other options

    Invalid token or wrong IP would cause different errors. Docker daemon not running would prevent any command execution.
  3. Final Answer:

    The node is already a member of another swarm -> Option A
  4. Quick Check:

    Node already in swarm = join fails with this error [OK]
Hint: Node must leave swarm before joining another [OK]
Common Mistakes:
  • Assuming token or IP is always the cause
  • Ignoring existing swarm membership
  • Not checking Docker daemon status
  • Trying to join without leaving first
5. You want to add a new worker node to an existing swarm. The manager node IP is 10.0.0.5 and the join token is SWMTKN-1-abc123. Which sequence of commands correctly adds the worker node and verifies it joined?
hard
A. On worker: docker node add --token SWMTKN-1-abc123 10.0.0.5
On manager: docker swarm ls
B. On manager: docker swarm join --token SWMTKN-1-abc123 10.0.0.5:2377
On worker: docker node ls
C. On manager: docker node join --token SWMTKN-1-abc123 10.0.0.5
On worker: docker swarm ls
D. On worker: docker swarm join --token SWMTKN-1-abc123 10.0.0.5:2377
On manager: docker node ls

Solution

  1. Step 1: Join the worker node to the swarm

    The worker node uses docker swarm join --token TOKEN MANAGER_IP:2377 to join the swarm.
  2. Step 2: Verify the node joined on the manager

    On the manager node, docker node ls lists all nodes including the new worker.
  3. Final Answer:

    On worker: docker swarm join --token SWMTKN-1-abc123 10.0.0.5:2377; On manager: docker node ls -> Option D
  4. Quick Check:

    Join on worker, list on manager = correct process [OK]
Hint: Join on worker, verify on manager with 'docker node ls' [OK]
Common Mistakes:
  • Running join on manager instead of worker
  • Using wrong commands like 'docker node add'
  • Trying to list nodes on worker node
  • Omitting port 2377 in join command
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard