Join a node to a swarm as a worker
In this step, we will learn how to join a node to an existing Docker Swarm as a worker. A worker node is a machine that runs the services deployed to the swarm. It receives and executes tasks assigned by the manager nodes.
Before joining a node to a swarm, you need to have a running Docker Swarm manager node. For this lab, we assume a swarm is already initialized and you have the join token for worker nodes.
First, let's simulate having a join token. In a real scenario, you would get this token from the manager node using the docker swarm join-token worker
command. For this lab, we will use a placeholder token.
Let's assume the join command provided by the manager is similar to this:
docker swarm join --token SWMTKN-1-abcdefghijklmnopqrstuvwxyz-1234567890abcdef --advertise-addr <THIS_NODE_IP> <MANAGER_IP>:2377
In this command:
docker swarm join
: This is the command to join a node to a swarm.
--token SWMTKN-1-abcdefghijklmnopqrstuvwxyz-1234567890abcdef
: This is the unique token that authenticates the node to the swarm.
--advertise-addr <THIS_NODE_IP>
: This flag specifies the IP address that the joining node will use to advertise itself to other nodes in the swarm. Replace <THIS_NODE_IP>
with the actual IP address of the node you are joining.
<MANAGER_IP>:2377
: This is the address of a manager node in the swarm. The joining node connects to this address to join the swarm. Replace <MANAGER_IP>
with the actual IP address of a manager node. The default swarm port is 2377.
Since we are working in a single VM environment for this lab, we will simulate the join process using a simplified command. We will use 127.0.0.1
as the manager IP and a placeholder token.
Execute the following command to simulate joining the swarm as a worker. Note that this command will not actually join a real swarm in this single VM setup, but it demonstrates the command structure.
docker swarm join --token SWMTKN-1-abcdefghijklmnopqrstuvwxyz-1234567890abcdef 127.0.0.1:2377
You should see output indicating that the node is attempting to join the swarm. In a real scenario, if the join is successful, you would see a message like "This node joined a swarm as a worker."