Introduction to Docker Swarm/ Definition
A docker swarm is one of the tools available inside Docker containers which are an open-source container orchestration platform/tool. It is also called the native clustering and scheduling tool of Docker. When the size of containers grows, it becomes very difficult to manage all of there that is where the role of Swarm comes in. It helps the developers and the Admins to manage and establish a cluster of the Docker nodes in the form of a single virtual machine.
The Concepts/key Terms Used for Docker Swarm
- Swarm – A swarm is made up of many Docker systems/hosts which are running in swarm mode.
- Swarmkit – A Swarmkit is used for implementing the layer of Docker’s orchestration.
- Task – A task comprises of commands and the container that should be run inside the container. The tasks are distributed by the swarm manager to the nodes.
- Nodes – Node can be defined as a singular Docker Engine and which are participating in the swarm. A good production swarm deployment is one that has the distributed docker nodes spread across many machines.
- Service – Whenever a service is created, it specifies the container which should be used and the commands that should be run inside the container. So service is a list of tasks that should be executed on the worker or the manager nodes.
- Manager Nodes – The job of manager nodes is to dispatch the tasks to the worker nodes. The manager nodes are also responsible for performing other functions such as managing the cluster and orchestration.
- Worker Nodes – The job of the worker node is to input the tasks that are coming from the manager node and run them. A worker node is installed with agents that report the units of the work assigned to it to the manager nodes.
- Leader Nodes – It serves as a leader to perform tasks related to orchestration.
What can one do by using Docker Swarm
Swarm is very useful for the administrators and developers in a Docker ecosystem. Following are some of the tasks the docker can achieve:
- It can be used to scale the number of containers.
- For establishing coordination between containers.
- For allocating tasks to the cluster of containers.
- For managing the lifecycle of containers and also for performing regular health checks.
- For serving the purpose of rolling out the updates for software among the containers.
Understanding Docker Swarm/Working
Below is the working of docker swarm which are as follows:
Working of Nodes
As we have seen, there are two types of nodes i.e. the manager and the worker. Let us look into the working of both.
The tasks that are handled by the manager nodes are – Scheduling the services, maintenance of the cluster state, and also fulfilling the HTTP API endpoints. It is advisable to run multiple manager nodes because that will help you to take the benefit of swarm’s fault tolerance features.
Worker nodes run the containers and it requires a minimum of 1 manager node in order to function.
4.6 (2,398 ratings)
Working of Services
The sole purpose of services is to deploy an app image to the Docker swarm. For example, a DB Server, Web Server, HTTP Servers are examples of services.
Processes and terms in service:
- Task Failure – Whenever a task fails inside a docker swarm, generally it is not restarted. So the job of the orchestrator is to remove that failed task and replace it with the new one which is in per with the state of the service.
- Service Option – Whenever a service is created, we can always define a port to which the service can be used on (for external users), memory and CPU limits can be applied, update policies can be defined, etc.
- Pending Service – A service goes into a pending state when no nodes are currently available in the docker swarm to run the task.
Docker Swarm Filters
The docker swarm is having 5 filters:
- Affinity – The purpose of affinity filter is to ensure that the containers are running on the same network node and it also defines the sequence in which the containers should execute.
- Port – The port defines a dedicated resource. When a container is running on the port which is not free, the container will shift to the other nodes that are available.
- Constraint – When a node is created, we can assign key-value pairs with the help of a constraint filter.
- Dependency – Whenever there is a dependency between the containers, dependency filters schedule those on the same node.
- Health – If any of the nodes are down and are not working, this filter will not assign any containers on it.
Some Docker Swarm Commands:
|Creating a Swarm||Docker swarm init|
|Joining a Swarm||docker swarm join \
–token Token_number \
|Creating a Service and Naming it||docker service create –name Edu|
|Removing a Service||docker service remove Edu|
|Updating Service||docker service update|
|Monitoring Node Health||docker node ls|
Advantages and Disadvantages
Let us now see the advantages and drawbacks of docker swarm
- Deployment is easy and the swarm mode is by default comes with Docker Engine.
- Installation is easy and fast.
- The swarm integration can be easily achieved with Docker CLI and Docker compose
- Not much experience is required and learning is easy.
- In order to scale the services, manual intervention is required.
- It is having limited fault tolerance.
- Not wider functions are available as of now.
- It has a smaller community as compared to other orchestration tools available like Kubernetes.
In this article, we have started with a basic overview and definition of Docker swarm and we also saw the important terms used in the swarm technology which is a part of the ecosystem. Then we have tried to understand the working behind Docker swarm and also learned a couple of Docker commands that are used in swarm mode.
This has been a guide to What is Docker Swarm?. Here we discussed the Concept, Command, filters, Use, and Understanding of Docker Swarm. You can also go through our other Suggested Articles to learn more –