In this post, we are going to discuss Docker and Virtual Machines and its key difference. Most of you are already familiar with the Virtual Machine and how it works. As the name suggests its virtualize a machine on top of a physical server. Let’s discuss in details, the below picture will give an overview of both docker and VM architecture.
The difference in the architecture of Docker and Virtual Machine
As you can see, both Docker and VM have an underlying infrastructure and Host OS. The infrastructure can be your PC and HOST OS is Operating system installed in it, windows, Linux etc. In Virtual Machine (VM), we have a layer know as Hypervisor also known as Virtual machine monitor. A hypervisor is a software which creates and run virtual machines on the host machine. In other terms hypervisor allows the host machine to have multiple VMs which will share the host machine resources like memory, processing etc. i.e its virtualize the hardware of the host machine. Examples for hypervisors are VMWare, Hyper-V etc.
On the other hand, we have a Docket engine layer on Docker architecture. Same as like hypervisor, Docket is a software which enables us to create container-based applications. Unlike VM, docker virtualizes the Operating System of the host machine where it is installed. The running container application in docker will be using the host OS kernel, and VM these applications will use the guest OS kernel.
What are the advantages of Docker?
Let’s discuss the advantages of using docker considering the below 4 points
- Memory Usage
- Portability
- Scalability
- Boot Uptime
Memory Usage
Consider you have two applications one is based on Windows or Linux. If you are using the VM to host these applications, you will be creating two VMs with guest OS Linux or windows, then we configure our application on top of it. As the VM have a host OS in it, it will consume some memory and the application will use the memory it needed. The problem here is if you allotted a certain memory to the VM while creating it we won’t be able to reassign the memory for any other purpose even if free memory left. When it comes to Docker, we are allocating the memory to the applications and if it’s not using 100% memory allotted, we can use the free memory for other applications.
As you can see in the image, you have a host machine which has 100 GB memory and you created 3 VMs with 30GB, 40GB and 30GB and configured the application in all these VMs. In each VMs, the host OS and application together using some memory and we have some free memory. But we won’t be able to assign this memory to any other application. On the other hand, the container applications will be using some memory from the allotted and the rest will be free. you can allocate this memory to other applications.
Portability
Consider you are developing an application based on Java. You have set up the environments and did some configuration to run your application. Once the development is completed, you need to test the application in a testing environment. You provided the detail to the tester. Here, before he starts working on the application testing, he/she need to set up the same environment and configurations you did. Only after this he/she will be able to test the application and its time consumed. Also as these communications between you and the tester will be in a text format, what happens if you missed mentioning an important point or when the tester missed to configure it? the application won’t work the same way it did on your end right?
When it comes to docker, we are building the docker images with all configuration, binaries and library files. the tester can use the same docker image to run the application on their end without worrying about the configurations or the library files needed for the applications. The same way we can move your code to the production environment as well in no time. isn’t it cool?
I know what you are thinking, we can create images for VMs as well. But the problem is the image will large in size and sometimes it’s tricky to have a live migration. Also, it’s not feasible for all times.
Scalability
This is one of the main selling points of Dockers. Compared to virtual machines, containers scale much more easily. That is because you can create a new container in seconds to increase the capacity for running service. Virtual machines take minutes to start. Also, as you see in our above discussion we can have more number of applications in a host machine compared to the same host which run the VMs.
Boot Up-Time
As we already discussed, the VM will take a minute to boot up as it has its own OS. But in docker, we can start the application in milliseconds.
both this scalability and boot up-time is important as we can move containers quickly between host environments to respond to a hardware failure or increase the load.
Hope this post gives you an idea about docker and VM and how it differs from each other. Let me know your feedback on the comment section below.