How to use Docker Swarm

In this tutorial we will see how to use Docker Swarm step by step, follow the steps below to learn using Swarm:

Step 1. So this is the Syntax of the command we need to create a new swarm on our docker desktop:

docker swarm init --advertise-addr <MANAGER-IP>

Hence we will enter the following command in our terminal:

docker swarm init --advertise-addr 192.168.99.100

If this doesn’t work in your computer, you can use:

docker swarm init --advertise-addr 127.0.0.1

Our swarm is now created. you will get a similar output:

Step 2. Now we can enter the following to check the state of the swarm:

docker info

This will give you the information about the swarm:

Step 3. if we enter

docker node ls

on the terminal. It will give us the list of nodes running and we can see our leader node there:

Step 4. In order to add a worker nodes to swarm you can enter the following command in your terminal

docker swarm join --token  SWMTKN-1-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv-8vxv8rssmk743ojnwacrr2e7c 192.168.99.100:2377

Step 5. Now let’s deploy a service in Docker Swarm, in order to deploy any service in swarm, in syntax of the command is:

docker service create –replicas[NUMBER OF REPLICAS] –name [NAME OF SERVICE] [IMAGE]

Therefore, we can enter the following command, to create a alpine service named gfg:

docker service create --replicas 1 --name gfg alpine ping docker.com

and your gfg service will be created:

Step 6. We can check our list of services using the following command:

docker service ls

you will find the gfg service in the list:

Step 7. Now let’s scale this service to 2 replicas, to do that the syntax for the command is:

 docker service scale [NAME_OF_SERVICE] = [NUMBER_OF_REPLICAS]

Enter the following command in your terminal to scale our gfg service to 2 replicas:

 docker service scale gfg=2

Step 8. Now when we check our list of services, we see that our gfg service has 2 replicas:

docker service ls

Step 9. Finally, we would want to delete our service, for that the syntax of the program is

 docker service rm [NAME_OF_SERVICE]

To delete our gfg service we can simply enter this command:

 docker service rm gfg

Upon checking the list of services, we will not find your gfg service anymore:

docker service ls

And with we will learn how to use Docker swarm, we create our first Docker swarm, then we created nodes and services and learned hot to scale them and remove them.

Docker Swarm: Building a Highly Scalable Cluster

Docker Swarm is one of the most popular container orchestration engines. It is not only used by professional engineers but also by people is their learning phase of how operations work. What makes Docker Swarm so popular is the fact that is very lightweight and very simple to understand – you don’t even have to learn a new CLI for Docker Swarm, we can use it with Docker CLI.

In this article, we will learn about Docker Swarm, its features, and use cases and will also go through a tutorial to create highly scalable clusters in Docker Swarm.

Similar Reads

What is Docker Swarm?

Docker Swarm is a container orchestration engine that was included by Docker as a part of its container runtime. Docker Swarm was included in the Docker container runtime in June of 2016....

Why we need Docker Swarm?

Let us take an example to understand the need of Docker Swarm. Let us say you have an application that is divided into 100 containers, now you will need to manage and control multiple containers at a time as a single service. This is called Orchestration – managing and controlling multiple containers as a single service. And this is what we use Docker Swarm for....

Features of Docker Swarm

We have many Container Orchestration tools in the market like Kubernetes, Apache Mesos etc. Kubernetes is even more popular Orchestration tool, Then why should Docker? Here are a few reasons to use Docker and some features of Docker:...

Docker Swarm Architecture

This is a high-level architectural view of Docker Swarm. In the diagram we have three manager nodes (similar to the Master nodes of Kubernetes). A node is an individual Docker Engine participating in the swarm. Swarm is a Mode which consists of multiple Docker hosts which run in a cluster. We always have an odd number of manager nodes. If we have a development or test environment where availability is not a big concern we can only use one manager node, but in production we will generally have either three or five manager nodes. Worker nodes are nodes where where the actual workloads are run. The workers nodes communicate with each other using the gossip protocol....

Swarm tasks and stacks

Swarm Tasks...

Tutorial – How to use Docker Swarm

In this tutorial we will see how to use Docker Swarm step by step, follow the steps below to learn using Swarm:...

Comparison between Docker swarm and Kubernetes

You might have heard about Kubernetes. A technology that is very much comparable with Docker Swarm is Kubernetes. Docker swarm is basically an alternative to Kubernetes which is a container orchestration tool. So instead of Docker Deamons, in Kubernetes you would have services called Kubelets that will run on each node and instead of Docker you would have a Kubernetes Engine that actually spends those multiple nodes that make up the cluster and the rest everything is almost the same. You have the same docker containers with the same applications running on that cluster set up....

Conclusion

So Docker Swarm is a really great orchestration tool and a really good alternative to Kubernetes if you are looking for a lightweight container orchestrator that can perform auto load balancing and not have auto scaling is not a issue for you. Docker Swarm comes pre installed with the Docker tool which is another plus point for Swarm as we don’t have to learn a new CLI interface in order to get Started with Swarm. All in all Swarm is a great choice for a simple and easy to use container orchestrator....

FAQs On Docker Swarm: Building a Highly Scalable Cluste

1. Is Docker Swarm Similar to Kubernetes?...