0% found this document useful (0 votes)
381 views4 pages

Docker Swarm

Docker Swarm allows administrators to create a cluster of Docker nodes that act as a single virtual system. It provides high availability and scalability by enabling failover if nodes go down and distributing containers across multiple servers. This document outlines the steps to create a Docker Swarm cluster using 2 Ubuntu servers - one as the manager node and one as a worker node. It then demonstrates deploying a simple Nginx service to the cluster that is replicated across both nodes.

Uploaded by

Vishal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
381 views4 pages

Docker Swarm

Docker Swarm allows administrators to create a cluster of Docker nodes that act as a single virtual system. It provides high availability and scalability by enabling failover if nodes go down and distributing containers across multiple servers. This document outlines the steps to create a Docker Swarm cluster using 2 Ubuntu servers - one as the manager node and one as a worker node. It then demonstrates deploying a simple Nginx service to the cluster that is replicated across both nodes.

Uploaded by

Vishal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

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

What we will do?


================
Configure Hosts
Install Docker-ce
Docker Swarm Initialization
Deploying First Service to the Cluster

Step 1 - Configure Hosts


========================
Before installing any packages for the swarm cluster, we will configure the hosts
file on both servers.

Run commands below on all servers, 'manager' and 'worker01'.

Edit the '/etc/hosts' file using vim editor.

#vim /etc/hosts

Add the following configuration to the end of the line.

<IPadress1> manager
<IPaddress2> worker01

Save and exit.

Now ping all the nodes using 'hostname' instead using IP address. (Doing this step
just to check the connectivity)

ping -c 3 manager (it should reply)


ping -c 3 worker01 (it should reply)
And make sure it's working at all hosts.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~

Step 2 - Install Docker-ce


==========================
To create the swarm cluster, we need to install docker on all server nodes. In this
step, we will install Docker-ce Community Edition on both servers manager and
worker01.

Install Docker-ce dependencies using the apt command below.

#sudo apt install apt-transport-https software-properties-common ca-certificates -y

Now add the Docker key and the Docker-ce repository to our servers.

#curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -


#sudo echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial
stable" > /etc/apt/sources.list.d/docker-ce.list

Update the repository and install Docker-ce packages using apt install command
below.

#sudo apt update


#sudo apt install docker-ce -y

After the installation is complete, start the docker service and enable it to
launch every time at system boot.

#systemctl start docker


#systemctl enable docker

*******Docker-ce is now installed on our server nodes*******

Next, we will configure docker to run as a normal user or non-root user.

Create a new user named 'user1' and add it to the 'docker' group.

#useradd -m -s /bin/bash user1


#sudo usermod -aG docker user1

Now login to the 'user1' user and run the docker hello-world command as below.

#su - user1
#docker run hello-world

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~

Step 3 - Create the Swarm Cluster


=================================

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.

#docker swarm init --advertise-addr <IPadress1>

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.

Run the docker swarm join command on the 'worker01' node.

#docker swarm join --token <token id created above> <IPaddress1>:2377

The 'worker01' node has been joined to the cluster.

Check it by running the following command on the 'manager' node.

docker node ls
Now you see the 'worker01' node has been joined to the swarm cluster.

The Swarm Cluster has been created.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~

Step 4 - Deploying First Service to the Cluster


===============================================
In this step, we will create and deploy our first service to the swarm cluster. We
want to create new service Nginx web server(also known as reverse proxy server)
that will run on default http port 80, and then expose it to the port 8080 on the
host server, and then try to replicate the nginx service inside 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.

#docker service create --name my-web --publish 8080:80 nginx:1.13-alpine

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.

Replicas and Scale the Service


------------------------------
Now we will make replicas for the 'my-web' service. We will make 2 replicas of the
'my-web' service, so the service is accessible on the 'manager' and 'worker01'
nodes.

To replicate the 'my-web' service, run the following command.

#docker service scale my-web=2

And after it's complete, check again using docker service command.
#docker service ls

And now the server has 2 replicates.

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.

You might also like