« Previous 1 2 3 Next »
Scale Your Docker Containers with Docker Swarm
Extending the Hive
Joining a Node to the Swarm
Now it's time to join nodes to the swarm. Remember the token you were given after initializing the manager? You'll need that now. The command to join a node to the swarm is
docker swarm join --token TOKEN 192.168.1.71:2377
where TOKEN
is the token generated by the swarm initialization.
When you run the command, on success, you will see that the node has been joined to the swarm (Figure 3). Run that same join
command on all the nodes you want in the swarm. Once you're done, head back to the manager and, again, issue the command:
docker info
You should now see that the swarm is active, the machine is serving as a manager, and a total of three machines are in the swarm (Figure 4).
To see the nodes listed, go to the manager and enter:
docker node ls
The three nodes are listed (Figure 5), with dockermanager as the Leader .
Deploying a Service
With an active swarm, you can now deploy your first Nginx container; go back to the manager and issue the command:
docker service create -p 80:80 --name webserver nginx
The breakdown of the above command is simple:
docker service create
instructs Docker you're creating a new service.-p 80:80
instructs Docker to use external port 80 for the service and route it to internal (within the container) port 80.--name webserver
instructs Docker to name the service webserver .nginx
is the image to be used for the service.
To make sure the new service is listed, enter:
docker service ls
You should now see that the webserver service is running on port 80 (Figure 6).
Scaling Your Service
At the moment, your service is only running on one node. Because you have three nodes available, why not scale it up to use all three? To do so, you instruct Docker to scale the webserver service to three nodes with the command (run on the manager):
docker service scale webserver=3
Docker will start deploying the service to all three nodes (Figure 7). To verify the service has been scaled to all nodes, enter:
docker service ps webserver
You should now see that the three nodes have the service running (Figure 8).
If the service goes down on any one node, it will automatically be restarted on the same node or, if the original node is no longer available, a different node.
« Previous 1 2 3 Next »
Buy this article as PDF
(incl. VAT)