What is Docker and Why do We Need It? [Docker-Part1]

What is Docker and Why do We Need It? [Docker-Part1]

What is Docker?

A formal definition of Docker

Docker is an open source software platform to create, deploy and manage virtualized application containers on a common operating system (OS), with an ecosystem of allied tools. -- By Stephen J. Bigelow

To put it simply, Docker is an open platform for building, running and shipping application, which serves the purpose to ensure that if the application you have developed is working on your own machine, it can run and function the same way on the other machines.

In order to get a better understanding of the above-mentioned statement, we need to have an overall concept of how application development workflow looks like.

App Development Workflow

Picture2.png

The picture above shows the overall workflow for app development. It comprised of development team, testing team, operation team as well as end users. Development team will first build the application, then ship it to testing team for checking and testing. Then when the application is passed the testing stage, it will then be shipped to operation team to deploy to the server and then the application is ready to serve end users.

When the development team build an application, using certain frameworks like Django, Express etc. these frameworks will need certain libraries, or some dependencies. Hence after the application is packed and shipped to testing team and when the testing team start the application, the first thing to do will be downloading the dependencies and libraries and here is where the issues arise. The app might not be working in a way that it worked in the development team's machines due to those dependencies & libraries installation issues.

tester: "Hey something went wrong, something went wrong because of you"

developer: "It was working on my machine but it's not working on your machine, so it's something wrong with your machine"

A blame game started between development team and testing team

Github Alone is Not Enough!!

Well, you might think that throughout the app development workflow, the teams will be using version control software/platform such as git & github anyway, so what's the problem?

This is because the application may need some extra dependencies or maybe some OS level features, which even you are not aware of which you have in your machine but the same thing is not there in the tester machine.

Ideal Solution

To avoid this problem, the ideal solution will be finding a way to ship entire framework & dependencies and give it to testing team. However, some dependencies and libraries are dependent on the OS, so you have to give the entire OS and that's not practically possible.

Hence, people found a solution- Virtual Machine (VM)

Virtual Machine & Hypervisor

Virtual machines encapsulate an entire OS with executable code on top of an abstracted layer of physical hardware resources.

To put it simply, a virtual machine is an abstract of a machine (physical hardware, for example GPU, storage, RAM etc.), we can imagine that a VM is a mini machine which contains of its own OS running inside our physical machine. One VM should serve one development application (project) only so that applications can be run in isolation inside VMs.

After we have done building our application, we pack VM to create image and ship out that image to testing team. The testing team will just use the image to start a VM in their machines and the application will be able to work in the same way as what development team does.

Hypervisor is used to create virtual machines. The Hypervisor is responsible for managing and provisioning resources—like memory and storage from physical machine to VMs.

VM is Not Perfect

Here are some problems of using VM:

1. Each VM needs a full blown OS

Each VM needs a full copy of an operating system that needs to be licensed, patched and monitored, so you have to invest a lot of money.

2. Slow to start

The entire operating system has to be loaded just like starting a computer, that why these VMs are slow to start.

3. Resource intensive

Each VM takes a slice of the actual physical hardware resources like GPU, memory and disk space, so if you have 8GB of memory, that memory has to be divided between different VMs, and at the end we have a limit for how many VMs that we can run on a machine, otherwise we are going to run out of hardware resources.

Then people figured out a concept named container to solve the problem.

A Better Solution - Container & Docker

Containers are something like hypervisors, the only difference in containers is we do not install new OS (kernel) for each application, all the containers will share the same OS. Docker is the software to create containers in our machines.

Once you done building your application, you just have to pack the container of the application to create image, and when this image goes to the testing team, they can create multiple containers based on the image.

Benefits of Using Docker (Container)

Containers are just like hypervisors, but with additional benefits which solve the problems of using hypervisors.

1. Lightweight

Containers are more lightweight, they do not need a full operating system, all containers in a single machine share the operating system of the host (physical machine), which means that we only need to license, patch and monitor single operating system, and also

2. Quick to start

Because of the operating system has already started on the host, a container can start up quickly, usually in seconds, sometime less.

3. Not resource intensive

Containers do not need a slice of the hardware resources on the host, therefore we do not need to give them specific number of CPU cores or memory or disk space, hence, with a single host, we can run ten or more containers side by side which we can hardly achieve in hypervisors.