Docker Swarm
Docker Swarm
============
Docker Swarm is a clustering and scheduling tool for Docker containers. With Swarm,
IT administrators and developers can establish and manage a cluster of Docker nodes
as a single virtual system.
Clustering is an important feature for container technology, because it creates a
cooperative group of systems that can provide redundancy, enabling Docker Swarm
failover if one or more nodes experience an outage
OR
Docker Swarm is a tool to create clusters of nodes that act as a single Docker
daemon so you can run containers along multiple servers as if they were being run
in a single node, with all the benefits you have when using a cluster, like high
availability, scalability.
-----------------------------------------------------------------------------------
--------------------------------
We will create a swarm cluster using 2 ubuntu server machines, 1 server node as a
manager and 1 another as a worker. And then we will try to deploy the simple Nginx
service to the swarm cluster.
Prerequisites
=============
2 or more - Ubuntu 16.04 Server
manager <IPaddress1>
worker01 <IPaddress2>
Root privileges
#vim /etc/hosts
<IPadress1> manager
<IPaddress2> worker01
Now ping all the nodes using 'hostname' instead using IP address. (Doing this step
just to check the connectivity)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~
Now add the Docker key and the Docker-ce repository to our servers.
Update the repository and install Docker-ce packages using apt install command
below.
After the installation is complete, start the docker service and enable it to
launch every time at system boot.
Create a new user named 'user1' and add it to the 'docker' group.
Now login to the 'user1' user and run the docker hello-world command as below.
#su - user1
#docker run hello-world
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~
In this step, we will create the Swarm Cluster of our nodes. And in order to create
the swarm cluster nodes, we need to initialize the swarm mode on the 'manager' node
and then join the 'worker01' node to the cluster.
Initialize the Docker Swarm mode by running the docker command below on the
'manager' node.
You will see 'join-token' has been generated by the 'manager' node.
Next, we need to add the 'worker01' node to the cluster 'manager'. And to do that,
we need a 'join-token' from the cluster 'manager' node, so make sure to write it on
your note.
docker node ls
Now you see the 'worker01' node has been joined to the swarm cluster.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~
Create Service
--------------
Create new Nginx service named 'my-web' and expose the HTTP port of the container
to the port 8080 on the host.
And when it's created, check using docker service command below.
#docker service ls
The Nginx service has been created and deployed to the swarm cluster as a service
named 'my-web', it's based on the Nginx Alpine Linux, expose the HTTP port of the
container service to the port '8080' on the host, and it has only 1 replicas.
And after it's complete, check again using docker service command.
#docker service ls
To check:
========
Open your web browser and type the manager node IP address with port 8080.
http://manager:8080/
http://worker01:8080/
If result is good, then The Swarm Cluster has been created, and the Nginx service
has been completed deployed to our Swarm Cluster.