Skip to main content

Deploy Your First Application in Docker Swarm

In this post we will go through the basic concept of the Docker Swarm and have some hands on experience of deploying application on Docker Swarm. You need to have basic knowledge about Containers to follow this post. Here, an article that describe the basic of the Docker Container.
Having only single container for each service is not good when it comes to the production environment since we also need high availability when one node is down. If one node is down, then there should be another node to take over the load to that particular service. Docker Swarm gives you an elegant way to handle multiple container. Docker Swarm control following functionalities for you to deploy containers easily.
  • Health Checks on the Containers
  • Launching a fixed set of Containers for a particular Docker image
  • Scaling the number of Containers up and down depending on the load
  • Performing rolling update of software across containers
swarm-diagram.png
Node is an instance of the Docker engine participating in the swarm.
Worker Node are the nodes that run containers as instructed by the Master Node.
Manager Node instruct Worker Node container status. In Docker Swarm, there can be multiple manger and worker nodes. Purpose of having multiple manger node is to maintain high availability for Manager nodes. Here, one node selected as the Leader Node which perform the container orchestration. Leader Node selected by the the algorithm know as Raft consensus algorithm. handle the Manager Node can be also act as Worker Node by default. Manager node responsible to do following tasks.
  • maintaining cluster state
  • scheduling services
  • serving swarm mode HTTP API endpoints
For this example I am using Play With Docker instance to deploy the swarm instead of testing it on local machine. You can create an account in https://labs.play-with-docker.com with your docker hub credentials (You can test it in your local machine as well. But I prefer this one since you don't need to install Docker). Once you logged in, you can create new instance with "Add New Instance" button in the top left corner. This will show you a terminal that can be tested our deployment.
For this example we are using sample code from the Github that contain all required coding implementation. This example contain five different services as describe below.
  • Voting-app This is a python server that provide interface to vote. Port set to 5000 to access the interface. Vote app send vote results into the Redis DB.
  • Redis Redis is a on memory key value database that used here to store vote data.
  • Worker Worker read vote data from the Redis DB and save it on PostgreSQL DB
  • PostgreSQL This database store vote data in database
  • result-app This is NodeJS application to publish the voting result over the port 5001
architecture.pngFirst you need to clone this Github repository into the newly created instant with following command.
Then move into the project folder with
cd example-voting-app
Next, start the application with Docker Swarm with following command.
docker swarm init
This command will generate all required Docker images from "/result" "/work" "/worker" by executing "Dockerfile" and start the docker swarm.
Once everything setting up, you can see few port numbers are showing on top of your webpage. Click on 5000 port to see the interface to put vote and click on 5001 port to see the results of the vote.
Hope you enjoy reading this article and see you in next article. Cheers :)

Comments

Post a Comment

Popular posts from this blog

Database Internel Architecture: SQLite

Introduction A database is an essential part of building a software system which used to store and read data efficiently. Here, We are going to discuss some architectural details of database implementation by using an early version of SQLite. SQLite is a small database application which used in millions of software and devices. SQLite invented by D.Richard Hipp in August 2000. SQLite is a high performance, lightweight relational database. If you are willing to learn internal of a database in coding level, then SQLite is the best open source database available out there with highly readable source code with lots of documentation. Reading later versions of SQLite become a little harder since it contains lots of new features. In order to understand the basic implementation of database internals, You should have good knowledge about data structures, some knowledge about Theory of Computing and how an operating system works. Here we are looking into the SQLite 2.5.0 version. Here ...

Weird Programming Languages

There are thousands of programming languages are invented and only about hundred of programming languages are commonly used to build software. Among this thousands of programming languages, there are some weird type of programming languages can be also found. These programming languages are seems to be called weird, since their programming syntax and the way it represent its code. In this blog we will look into some of these language syntax. Legit Have you ever wonder, when you come to a Github project that print hello world program, but you cannot see any codes or any content. Check this link  https://github.com/blinry/legit-hello  and you will see nothing in this repository. But trust me, there is hidden code in this project. If you see the  commit  section, you can reveal the magic. Yeah, you are right. Its storing hello world code in inside the git commit history. If you clone this project and run the following command, then you can see the hidden code i...

Basic Concepts of the Kubernetes

Handling large software which has multiple services is a tedious, time-consuming task for DevOps engineer. Microservices comes into the rescue DevOps engineers from all these complicated deployment processes. Simply, each microservice in the system has it own responsibility to handle one specific task. The container can be used to deploy each of these micro-tasks as a unit of service. If you are not that familiar with Containers, read this article to get to know about Docker, Which is the most popular and widely used container technology to deploy microservices. As I described early, we can use single container to deploy a single service and container contain all required configurations and dependencies. Single service always faces a common problem of a single point of failure. In order to avoid single point failure, we need to set up another service such that if one service is getting down, next available service takes that load and continue to provide the service. Another requi...