📖 Scenario: You are setting up a Docker Swarm cluster to manage containerized applications. The cluster has one manager node and one worker node. You will create the initial swarm, add a worker node, and verify the nodes in the swarm.
🎯 Goal: Learn how to initialize a Docker Swarm manager node, add a worker node to the swarm, and list the nodes in the swarm.
📋 What You'll Learn
Use docker swarm init to create the manager node
Use docker swarm join with the correct token to add a worker node
Use docker node ls to list all nodes in the swarm
💡 Why This Matters
🌍 Real World
Docker Swarm is used to manage and orchestrate containers across multiple machines, making it easier to deploy and scale applications.
💼 Career
Understanding manager and worker nodes in Docker Swarm is essential for roles involving container orchestration, cloud infrastructure, and DevOps automation.
Progress0 / 4 steps
1
Initialize the Docker Swarm Manager Node
Run the command docker swarm init --advertise-addr 192.168.1.100 to initialize the current machine as the manager node with the IP address 192.168.1.100.
Docker
Hint
The --advertise-addr option sets the IP address the manager node uses to communicate with other nodes.
2
Get the Worker Join Token
Run the command docker swarm join-token worker -q on the manager node to get the worker join token.
Docker
Hint
The -q option outputs only the token string, which is needed to join worker nodes.
3
Join the Worker Node to the Swarm
On the worker node, run the command docker swarm join --token 192.168.1.100:2377 replacing <token> with the token from Step 2 to join the swarm.
Docker
Hint
Replace <token> with the actual token string you got from the manager node.
4
List All Nodes in the Swarm
On the manager node, run docker node ls to list all nodes in the swarm and verify the worker node has joined.
Docker
Hint
The docker node ls command shows all nodes and their roles in the swarm.
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
Step 1: Understand the role of manager nodes
Manager nodes control the swarm and decide which tasks run where.
Step 2: Compare with worker nodes
Worker nodes only run tasks assigned by managers, they don't control the swarm.
Final Answer:
To control the swarm and assign tasks to worker nodes -> Option C
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
Step 1: Recall the command to start a swarm
The command docker swarm init initializes the current node as a manager.
Step 2: Check other options for correctness
Other commands like docker node create or docker swarm start do not exist or are invalid.
Final Answer:
docker swarm init -> Option B
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
Step 1: Understand 'docker swarm init' effect
This command makes the current machine a manager node in the swarm.
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'.
Final Answer:
A list showing one manager node with status 'Ready' and availability 'Active' -> Option A
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
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.
Step 2: Check other options
Invalid token or wrong IP would cause different errors. Docker daemon not running would prevent any command execution.
Final Answer:
The node is already a member of another swarm -> Option A
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
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.
Step 2: Verify the node joined on the manager
On the manager node, docker node ls lists all nodes including the new worker.
Final Answer:
On worker: docker swarm join --token SWMTKN-1-abc123 10.0.0.5:2377; On manager: docker node ls -> Option D
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 unknownstrongwhile earning +1 Grip toward your certificate.