Sunday, January 29, 2017

How to Install Docker on Amazon EC2 Redhat Linux?

How to Install docker on EC2 Redhat Linux?

Let's see how to install docker on EC2 on Redhat Linux.

1. OS requirements - You need the 64-bit version of Redhat Enterprise Linux 7.
2. Remove unofficial docker packages. Sometimes your machine can contain older version of Docker with the package name docker instead of docker-engine.
    You can uninstall by executing the below command:
    $ sudo yum -y remove docker

Install Docker    You can install Docker in three different ways, depending on your needs:

    1. Install from Docker's repositories. This is the recommended approach.
    2. Download the RPM package and install it manually and manage upgrades completely manually.
    3. Some users cannot use third-party repositories, and must rely on the version of Docker in the Red Hat repositories. This version of Docker may be out of date. Those users should consult the Red Hat documentation and not follow these procedures.

 Install using the repository(recommended approach)
Before you install Docker for the first time on a new host machine, you need to set up the Docker repository. Afterwards, you can install, update, or downgrade Docker from the repository.
Set up the repository

    Install yum-utils, which provides the yum-config-manager utility:

    $ sudo yum install -y yum-utils

    Use the following command to set up the stable repository:

    $ sudo yum-config-manager \
        --add-repo \

Install Docker

Update the yum package index.

$ sudo yum makecache fast

If this is the first time you have refreshed the package index since adding the Docker repositories, you will be prompted to accept the GPG key, and the key’s fingerprint will be shown. Verify that the fingerprint matches 58118E89F3A912897C070ADBF76221572C52609D and if so, accept the key.

Install the latest version of Docker, or go to the next step to install a specific version.

$ sudo yum -y install docker-engine

On production systems, you should install a specific version of Docker instead of always using the latest. List the available versions. This example uses the sort -r command to sort the results by version number, highest to lowest, and is truncated.

    Note: This yum list command only shows binary packages. To show source packages as well, omit the .x86_64 from the package name.

$ yum list docker-engine.x86_64  --showduplicates |sort -r

$ sudo yum -y install docker-engine-<VERSION_STRING>

Verify that docker is installed correctly by running the hello-world image.

$ sudo docker run hello-world

Is Docker daemon running error? Can not connect to the Docker daemon error..

Did you get this error after installing Docker on any of Redhat Linux OS or Amazon Machine image?
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.

See 'docker run --help'.

Fix for the above issues:

Just do the below to fix the error..

Firstly make sure docker daemon is running by executing the below command..
> service docker status
After executing if see you some thing like this, docker is not yet started.
docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
   Active: inactive (dead)

you can start by executing the below command:

>service docker start

 docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
   Active: active (running) since Sun 2017-01-29 13:40:17 EST; 1s ago     Docs:
 Main PID: 30319 (dockerd)

> service docker status

Now you should see docker daemon is running.
now execute the below command to run hello world docker image.
> sudo docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

Monday, January 23, 2017

What is Microservices all about? Best Practices in building Microservices architecture

You are brewing your morning Coffee at your work and you are hearing words such as DevOps, CI/CD, Microservices, Docker.. well, you are not alone..Most of the companies are at least trying to start microservices for a new development..or they are thinking to migrate from existing monoliths. Before we deep dive into that topic, let's try to understand what is monolith(traditional web/ear) application. Monolith is usually a single large web app which has everything built-in. A small code change in UI requires a build, deployment and test, even you did not modify code in business or data layer. Also, if you would like to scale out a particular layer, it is difficult as it requires a deployment of whole WAR on new instances. Here comes the Microservices to solve some of the issues.

What is microservices?

Breaking a large application into a set of simple services, also called as functional decomposition.
Each services can be independently developed and deployed
Modular approach to system-building
Each service have its own persistent storage
Microservices  are independent in code, technology,  scaling.

Architecture difference between Monolith and Microservices

Microservices is an architectural approach of breaking application (functional decomposition) into smaller services where each service can be independently developed, deployed with no limitation to technology stack. Yes. It can be scaled out without impacting other services.

But trickier question is when should I use use microservices? Answer is it depends..If you are developing a large or complex application from scratch, start with microservices architecture by separating UI, business and data layers. If you already have a large app deployed to production which becomes a hard mountain to climb, you can address this problem in this way.

How to re-factor your existing monolith into microservices architecture?

  1. Implement any new functionality as microservice. 
  2. Split the presentation components from the business and data layer.
  3. Incrementally refactor your application into a set of microservices without fully decommissioning the monolith app.
  4. Re-factor your monolith incrementally.
Here are some of the best but simple practices to consider when developing microservices.

Best practices on developing Microservices

  1. Design for failure(fault tolerance)
  2. Use one repository per service
  3. Each service should have independent CI/CD pipeline
  4. Each service should be loosly coupled
  5. Incrementally refactor your application into set of microservices when migrating from monolith
  6. Create a separate data store for each microservice.
  7. Deploy microservices in containers(docker)
There are few drawbacks too when implementing them.

Drawbacks of Microservices

  1. Developing distributed system can be complex.
  2. Multiple databases and transaction management can be painful.
  3. Testing Microservices based application can be cumbersome.
  4. Deploying Microservices can be complex as it requires co-ordination among multiple services