Docker Swarm: Container Orchestration Using Docker Swarm

Share At:


A swarm consists of multiple Docker hosts that run in swarm mode and act as managers (to manage membership and delegation) and workers (which run swarm services). A given Docker host can be a manager, a worker, or perform both roles.

When Docker is running in swarm mode, you can still run standalone containers on any of the Docker hosts participating in the swarm, as well as swarm services. A key difference between standalone containers and swarm services is that only swarm managers can manage a swarm, while standalone containers can be started on any daemon.

In this demonstration, we will see how to configure the docker swarm and how to perform basic tasks.


  1. For our demonstration, we will be using centos-07.
  2. We will be using 3 machines for our lab, 1 machine as a swarm Manager node and 2 swarm worker nodes. These servers have below IP details:

3. The memory should be at least 2 GB and there should be at least 2 core CPUs for each node.

Please perform steps (1–4) on all the nodes — Master nodes and Worker nodes:

  1. Set the hostname and update /etc/hosts file.

2. Run below Docker installation script. This script will do the installation for you.

curl -fsSL | sh

3. Once the docker has been installed, add the “vagrant” user to be part of the “docker” group.

4. Now “start” and “enable” the docker service.

Our docker has been installed, configured, and now ready for use.

Now to Initialize the docker swarm, run the below Commands as mentioned below:

5. On Master Node Only:

docker swarm init — advertise-addr

Running the above command will generate a token that will be used for other worker nodes to join the swarm. In our case we have the below output:

docker swarm join — token SWMTKN-1–4jc5twl7y7fo0rey8s4x100hk7zekj1ww8fnqt6m2jz2nj7vnl-1zd68yh4xy4v67oe8lr4ou131

6. On Worker Nodes only: Run below Docker swarm join command on all the worker nodes to join the swarm:

docker swarm join — token SWMTKN-1–4jc5twl7y7fo0rey8s4x100hk7zekj1ww8fnqt6m2jz2nj7vnl-1zd68yh4xy4v67oe8lr4ou131

You will get output like “This node joined a swarm as a worker” after successful join.

7. On Manager Node: Run the command “ docker node ls”. This will show that two worker nodes have joined the swarm cluster. You will also notice that our manager node is shown as leader.

Our Docker Swarm cluster is ready for use now.

Performing simple Deployment to see the functioning of docker swarm:

Now let’s create a service for Docker swarm and deploy a container inside it.

8. Running the below command on manage rnode will deploy a container named “helloworld” using “alpine” as base image and will create 1 replica of it“ping” section is used to keep the container alive.

docker service create — replicas 1 — name helloworld alpine ping

9. The “docker service ls” command will show that 1 replica of the container is running.

10. If you need more information related to the service, run the below command:

docker service inspect — pretty helloworld

Scaling up the Deployment:

11. Now below command will scale up our deployment to 3 replicas:

docker service scale helloworld=3

12. Below command will show on which nodes the container is running:

docker service ps helloworld

Deleting a service:

13. Run the below command to delete our service called “helloworld”.

docker service rm helloworld

14. Running “docker service ls” shows no service is running.

This concludes our tutorial for “Container Orchestration Using Docker Swarm”.

Happy Learning !!!

Share At:
0 0 votes
Article Rating
Notify of
Inline Feedbacks
View all comments
Back To Top

Contact Us