
Container orchestration in Docker Swarm – introduction

Containerization of the application with Docker has recently become quick, easy and pleasant. Docker, however, does not allow advanced management of containers created with it. Therefore, the next natural step was the emergence of container group management systems. Today a few words about orchestration. The leader of the orchestra at the time of writing this […]
Containerization of the application with Docker has recently become quick, easy and pleasant. Docker, however, does not allow advanced management of containers created with it. Therefore, the next natural step was the emergence of container group management systems. Today a few words about orchestration.
The leader of the orchestra at the time of writing this article (August 2020) is Kubernetes. However, let us not limit ourselves to using this only „correct ” solution. It may often be easier and faster to launch the orchestra system under the name Docker Swarm, developed since 2016. In today’s article, we’ll look at its possibilities.
Docker Swarm ( swarm) is one or more physical or virtual machines that can run containers as services. Each node after joining Swarm can be both a work node and a manager. At Docker Swarm, there is no need to run managers as separate nodes, the product itself has a built-in automatic load balancer. In planting, it does not require any administration, although it is certainly not as advanced as, for example. HAProxy or NGINX. A big plus in favor of Docker Swarma is the automatic encryption of connections between nodes.
With Docker installed, we have the Docker Swarm system immediately available. Using the command:
docker swarm init
we can initiate a cluster.
The above operation is possible only on one server. If we need to add more machines, we can execute the command:
docker swarm join - token < ...>
As we guessed, the token is a random string from the master server. We see this token on the screen during the initialization of Docker Swarm. We can also get it with the -q parameter with the manager or worker switch:
docker swarm join-token -q worker
We can manage IP addresses using parameters --advertise-addr
and --listen-addr
. We can use them in the docker swarm init command. Parameter --advertise-addr
allows you to set the addressing inside the cluster, while --listen-addr
allows you to determine the IP address to connect to the manager.
Other useful commands are, for example:
docker node ls
and
docker node ls -f
where we can filter displayed items by fields: id, label, membership, name, roles.
Displaying services operating within the service cluster is possible using the command:
docker service ps
More detailed information can be displayed using the command:
docker node inspection
We can also display information in a more transparent form using the command:
docker node aspect --format = pretty self
Equipped with such basic information, we can proceed to launch a simple service in the cluster. We start by initializing the cluster:
docker swarm init
Because we didn’t provide any additional parameters, Docker himself accepted IP addressing for the network. He also displayed the token mentioned earlier.
Let’s add a service to our cluster. Based on the EuroLinux 7 container, we will use the image of the httpd Apache server here.
First, we download the image locally:
docker pull eurolinux / apache
Then we launch the server in our cluster with replication of up to 5 services:
docker service create -p 80:80 --name ApacheEuroLinux --replicas 5 eurolinux / apache
Let’s check the operation of our services:
docker service ps ApacheEuroLinux
In the browser we can see the welcome website of the web server:
http://192.168.88.13
We can also use the „clean ” Doker command to view working containers:
docker ps
Note the NAMES column and ID column from the previous dump:
Deleting the service is possible using the command:
docker service rm ApacheEuroLinux
Summary
As we have already mentioned, when installing Docker we also get Docker Swarm. It is certainly an easier tool for people starting their adventure with container orchestration than Kubernetes. In many places, it facilitates the initial start, because by issuing one command docker swarm init
we get a fully operational orchestration system. This allows us to quickly launch the environment both for the needs of the development team and for our own use. On the other hand, we must remember that being isolated from certain configuration issues, we may have difficult options to solve any problems. Nevertheless, Docker Swarm remains the lightest and simplest orchestration system. Time will tell you what the fate of this project will be, but people interested in containerization technology should get to know this product better.