The release of Docker Engine v1.12 introduced swarm mode for creating and managing a cluster of Docker Engines, which is referred to as a swarm. This replaces Docker Swarm, which was previously a separate application.
A Swarm is a collection (cluster) of nodes running Docker Engine following a decentralized design where services can be deployed. Swarm mode includes scaling, service discovery, desired state and many other features. For an overview of Swarm mode highlights, see our post on Docker Swarm Integrated into Docker Engine.
By using the CenturyLink Cloud plugin for Docker Machine, customers can create a Docker swarm on the CenturyLink Cloud by running a small number of Docker machine commands to create the nodes. Thus allowing the ability to run the Docker CLI commands required to create the swarm by setting the machine context using Docker Machine.
The following requirements are needed to create a Docker swarm in CenturyLink Cloud:
If you don’t have a CenturyLink Cloud account yet, no problem. Just head over to our website and activate an account.
Creating a Docker swarm is composed of many steps. For this tutorial the steps have been divided into the following sections:
Environment Setup Node Creation Creating the Swarm Adding Manager Nodes Adding Worker Nodes Validating the Cluster
1) Decide how many manager and worker nodes you want in your swarm. The following table contains some advice:
By default the manager nodes will be used to run tasks in addition to the worker nodes. The manager nodes are used to submit tasks and they perform the management and orchestration function of the swarm.
If you are new to the ideals behind the protocol for implementing distributed consensus(RAFT), visit this slideshow for more information.
2) Open a command prompt and set the CLC_USERNAME, CLCPASSWORD and CLC_ALIAS environment variables for your CLC account. For example on Linux & OSX:
docker-machine create -d clc --clc-server-group "DockerSwarm" --clc-server-location "GB3" MANAGER1
The notes from step 1) apply to the worker nodes as well.
3) Once the nodes have been created run the following command to view all of the Docker hosts that have been created:
The output should be similar to the image below:
Create the Swarm
1) Set the Docker environment variables for the first of the manager nodes by running:
docker-machine env MANAGER1
Depending on your OS the command will output a command that can be used to set the required environment variables. Por exemplo:
eval $(docker-machine env MANAGER1)
2) Create the swarm by running the following command:
docker swarm init
The command output will contain a command that will be used later to join worker nodes to the swarm. Save the command for later use:
IMPORTANTE. There are a number of command line options that can be specified when creating the swarm. Visit this document for more information.
Adding Manager Nodes
1) While the Docker environment variables are still set to the first manager node run the following command:
docker swarm join-token manager
This output will contain the command that will be used to join additional manager nodes to the swarm:
2) Set the Docker environment variables for the manager node to join to the existing swarm by first running:
docker-machine env MANAGER2
Once again, depending on your OS the command will vary. This output will contain a command that can be used to set the required environment variables:
eval $(docker-machine env MANAGER2)
3) Run the command that was output in step 1). Por exemplo:
docker swarm join \ --token SWMTKN-1-2lptlwq6p1ddt0t6qpil2p904qlmrwnrik7f5a2c0gdvvs7hn4-cuxeu68q9ec159axrciz6wbqf \10.105.30.12:2377
The output of the command should indicate that the node joined the swarm as a manager.
4) Repeat steps 2) & 3) for each of the remaining manager nodes that need to join the swarm.
Adding Worker Nodes
1) Set the Docker environment variables for the worker node to join to the existing swarm by first running:
docker-machine env WORKER1
Based-on your OS, run the command from the output to set the require environment variables. Por exemplo:
eval $(docker-machine env WORKER1)
2) Run the command that was the output in step 2) of the Create the swarm section. Por exemplo:
docker swarm join \ --token SWMTKN-1-2lptlwq6p1ddt0t6qpil2p904qlmrwnrik7f5a2c0gdvvs7hn4-138uv6z599o1q9gki9wzwumn7 \ 10.105.30.12:2377
The output of the command should indicate that the node joined the swarm as a worker.
3) Repeat steps 1) & 2) for each of the remaining worker nodes that need to join the swarm.
Validating the Cluster
1) Run the following command to list all the nodes in a swarm with their status:
docker node ls
Output should be similar to the image below:
This output shows important information including the status of each node and which manager has been elected the leader.
Now that you have a working Docker swarm running in CenturyLink Cloud, you are ready to start managing and deploying services to the swarm. It is recommended that you follow the swarm mode tutorial.
You can find more Docker tutorials and Resources below, or just search 'Docker' or 'Containers' in the search field on Developer Center home page.