How to create a Docker Swarm Cluster
Today we will show you how to set up a Docker Swarm Cluster on gridscale.
After showing you how to install Docker on Ubuntu 16.04, today we want to go one step further. Want to expand your development environment and run a copy of your application stack on multiple system environments? With Docker Swarm, you can easily deploy your container applications to many systems in the cloud. The whole thing is called container orchestration.
The great thing about it is that Docker Swarm has been Docker-native since version 1.12. This means that you don’t have to install anything but Docker on your systems to set up a Docker Swarm. In the following tutorial we will set up a Docker Manager with 2 workers.
To give you a basic understanding of what happens later on your screen, we’ll briefly clarify what Manager Nodes and Worker Nodes are.
Manager-Nodes: The managers take on tasks related to cluster management.
– Monitoring the clusters
– Scheduling of services
– And how to use the Docker Swarm API Endpoints
Sounds good, but what exactly is scheduling?
In “scheduling”, a service file is placed on the hosts, which is managed like a specific container. In container orchestration, in a more general context, one often hears of a “scheduler”, so a scheduler has to be understood in a somewhat differentiated way. In a broader sense, it is responsible for hooking into the init of hosts and providing the services there in the desired capacities.
Worker-Nodes: The tasks of the worker nodes are separate from those of the manager nodes. The main task of the workers is to execute the containers. Worker nodes are subordinate to Swarm Managers, so we need at least one Manager node for our setup. You also need to know that all managers can act as workers at the same time.
Little docker tip for later: You can configure your managers in a multi-node swarm so that they do not accept tasks from a scheduler. Set the status of a manager to drain mode. If tasks are already running on the manager, they will be stopped and passed to an active node. Use the following command for this:
docker node update --availability drain
In our example we use a setup from 3 servers. Since we use Ubuntu 16.04 for our tutorial, you can use our gridscale template for the creation. How to create a gridscale cloud server is shown in our tutorial How to gridscale.
You need Docker on all 3 Hosts (min. version 1.12).
Forgot how to install Docker? In our tutorial “Docker on Ubuntu 16.04 LTS – a simple recipe” we show you how to do it!
Tip: If you have set up your first host with Docker, you can then simply use our snapshot function and clone two new servers.
Now that we’ve set up our 3 Linux hosts with IP address and docker, we’re ready to breathe life into our swarm.
So that all nodes within a swarm can communicate with the manager, it is important that all hosts can also communicate with each other.
Configure Swarm Manager
In the second step we configure the Swarm Manager. Connect to your first machine via ssh and execute the following command:
docker swarm init --advertise-addr 18.104.22.168
The Docker daemon responds to your command as follows:
root@server-dlns13ru:~# docker swarm init --advertise-addr 22.214.171.124 Swarm initialized: current node (74k3wszor5e9k0mczdqf17jn8) is now a manager.f To add a worker to this swarm, run the following command: docker swarm join \ --token SWMTKN-1-254dwy02zm1292gv66cxi7yn9odggm0z15ju3pt02udb940g5n-0ecfbhlml1tswy51djdgpb0ow \ 126.96.36.199:2377 To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
With this command you have just generated a Docker Manager including Swarm. The answer from the Docker Daemon confirms the creation of a Swarm Manager. In addition an ID “74k3wszor5e9k0mczdqf17jn8” was created for the new node.
The flag –advertise-addr assigns the manager the IP 188.8.131.52.
Furthermore, the answer will return a command to add Swarm Workers. Pretty simple, isn’t it? When you have added the Swarm Worker, check out the current status of your Docker Swarm with
A complete node command overview with explanations can be found with the command:
The third step is to add the workers to the created Docker Swarm.
To do this, first switch to one of your other two hosts via ssh. Now execute the command that was returned to you when you created the swarm with docker swarm init:
Then repeat step 3 on your remaining host.
If you don’t have the command at hand anymore, you can use :
docker swarm join-token worker
to copy what the code is and to create a swarm worker.
To track how your swarm is composed now, visit your swarm manager and run docker node ls.
This status overview can only be executed on a Docker Manager. The manager column shows you who your swarm managers are with the flag “Leader”. The * indicates to which Docker-Node you are currently connected. Your overview should now look something like this:
Not that hard, is it? You just created your first Docker Swarm!
Docker Swarm’s easy access to the Docker Command Line Interface (Cli) makes Docker Swarm a very user-friendly container orchestration tool.
Of course, the Swarm only makes sense when you provide services, as you’ll learn in the second part of the tutorial. Just sign up for our tutorial newsletter on the right side, we will inform you as soon as part 2 goes online!
Want more of Docker?
In our article Docker Swarm vs. Kubernetes: Comparison of both container management tools you can find more information about Docker.
Zurück zur Tutorial Übersicht Back to Tutorial Overview
Today we will show you how to set up a Docker Swarm Cluster on gridscale. After showing you how to install Docker on Ubuntu 16.04, today we want to go one step further. Want to expand your development environment and run a copy of your application stack on multiple system environments? With Docker Swarm, you […]
Vielen Dank für dein Feedback!
Wir melden uns bei dir, sobald der Artikel zu deinem Wunschthema fertig ist.