Docker Swarm is referred to as the orchestration and clustering tool that is used for containers. Basically, a docker swarm is built into the Docker Engine for the disseminated system comprising hundreds of different containers. Docker Node, Docker Services, and Docker tasks are key components of Docker swarm architecture.
If you want to enrich your career by advancing in Docker Swarm Architecture then enroll in "Docker Certification Training".This will help you achieve excellence in your domain.
Docker Swarm Architecture and Components
The major components of a docker swarm architecture include Docker tasks, Docker services, and Docker node.
1. Docker Node:
Included in the docker swarm, this one is a docker engine instance that is further divided into two different types:
2. Manager Node:
Manager nodes are basically liable for all of the container management and orchestration tasks needed to regulate the system in a specific state, like servicing the swarm mode HTTP endpoints, scheduling of the services, and maintaining the state of the cluster.
3. Docker Service:
This one is referred to as the task definition which must be executed.
4. Representative Docker Swarm Architecture
- To understand a typical docker swarm architecture, jotted down below are some of the key points that make it an easy-to-understand concept:
- For the docker swarm architecture, a node is a primary member.
- It is possible for the swarm architecture to have multiple manager nodes controlled by one manager node that is elected with the help of the Raft algorithm.
- Although capable of working in the form of a worker node; however, a manager node cannot be configured or altered to work as both manager and worker node at the same time.
- To manage and regulate the state of the cluster internally, a manager node uses the Raft Consensus Algorithm. This is to make sure that all of the manager nodes that have been scheduled to control tasks in the cluster are stored or maintained in a consistent situation.
- A swarm is referred to the cluster of nodes or docker engines where services can be deployed.
- Initially, the docker came with a system of cluster management with a specific communication protocol called Beam.
- Later, more APIs were added and renamed as a swarm. Thus, the first-generation swarm is known as swarm v1.
[Related Article: Docker Images and Containers]
Docker Swarm Workflow
Subscribe to our youtube channel to get new updates..!
The docker swarm workflow comprises the understanding of how services and nodes work in the docker swarm architecture. Here is the step-by-step explanation to comprehend the workflow in a better way.
- The first and foremost step will be to develop a docker-machine set that will be acting as nodes in the docker swarm. Among these, one is going to be the manager, and the rest will be the worker nodes. In order to create the docker-machine, below mentioned command is used on Windows, and then the docker terminal is launched.
docker-machine create –driver hyperv manager1
- Here, ‘manager1’ is the name of the docker-machine that lists the machines as well as their run.
docker-machine ls docker-machine ip manager1
- The next step will be the creation of worker machines. Here are three different commands to create varying worker machines.
docker-machine create –driver abcd worker1 docker-machine create –driver abcd worker2 docker-machine create –driver abcd worker3
- Using the below command, the manager or worker can be connected to get inside the machine.
docker-machine ssh manager1/worker1
[Related Article: Docker Security]
- The next step is to initialize the Docker swarm. On the machine that should be worked as a manager, this command should be run to make a node manager.
docker-machine ssh manager1 docker swarm init –advertise-and Manager1 IP
- The fourth step helps to join the worker nodes to swarm. This can easily be done by using this below command on the manager machine and running the received command on the worker machine that has to be made a worker.
Docker swarm join-token worker1
To evaluate whether the worker has joined the swarm, go to the manager machine and run the command. It will then list the added worker machine along with the details of the manager.
- Step five helps run the standard docker command on the manager.
- The following step is to run the docker containers on the docker swarm. With this, any service and replicas can be created. For that, visit ub.docker.com and log in. Thereafter, visit Explore Depositaries, where you can see different engine images. Services and replicas can be created by using this command.
docker service create –replicas 3 -p 70:70 –name sample Nginx
- Here, ‘sample’ is the name of the service and 70 is the port that is exposed. To check the service’s status, use this command on the manager node.
docker service ls docker service ps sample
- Then, check the service running on all of the nodes along with the browser by providing IP for all of the nodes.
- Now, the next step is to see the real use of the docker swarm, where services can be scaled up and down. On the manager machine, run this command to scale the service.
docker service scale sample=4
- This command mentioned above will run the service sample on 4 nodes. Even if all of the nodes are busy already, another service on worker or manager will be created. Similarly, a service can be scaled down using this command.
docker service scale sample=2
- The node can also be inspected to get different details, such as which service and how many of them are running on a node. To do so, the manager node will be used to run thi command.
docker node inspect worker1/manager1 docker node inspect self
- This step is to update the service when it is running on different machines. Also, updating the service is quite an easy process. For illustration, if you wish to update the nginx service’s version, you’ll use this command:
docker service update –image nginx:1.10.0 sample
- This one is the last step that helps with the shutdown, stop or removal.
- To shut down any specific node, this command will be used.
docker node update –availability drain worker1
- From all the machines, to remove a specific service, this command will be used:
docker service rm sample
- And, for a machine to stop altogether, you would have to run these commands in the docker terminal.
docker-machine stop worker1 docker-machine rm worker1
[Related Article: Docker Interview Questions]
Advantages of Docker Swarm Architecture
- Here are some of the pointers that represent the advantages of a docker swarm architecture:
- Swarm clusters can be easily managed by swarm command.
- To build an entire swarm, only a single point of access is required.
- In comparison to Kubernetes, docker swarm architecture is extremely simple and straightforward.
- The architecture comes with high availability; thus, even if the master fails, some other worker node will be taking the charge.
- The manager is going to keep a track of the state of the cluster so as to keep the consistency between the actual and desired state.
Being one of the simplest tools, the Docker swarm can be used to accomplish a variety of tasks. With a swarm, a docker offers orchestration as per the requirement. Furthermore, when it comes to set up and management, even that is a hassle-free task.