In my previous articles about containers, I tried to explain the containerization of applications and the high-level architecture of containers.
My previous article links are below,
In this article, I will try to explain the difference between containers and virtual machines.
Virtual machines are used widely in production environments and data centers. It is possible to create virtual machines in our desktops or laptops using a virtualization technology like hyper-v of Windows
Some people are saying containers are going to replace virtual machines. But, it seems not true.
Containers and virtual machines have their own pros and cons.
Let's try to understand the difference between containers and virtual machine using the below diagram.
As we can see in the above diagram, we have 3 different applications virtualized in 3 different virtual machines. Each virtual machines have its own operating system and its licenses. We need to maintain all these virtual machines individually with proper updates and configurations. Each virtual machine will run on top of the hypervisor we selected. It could be Microsoft Hyper-V, VMware vSphere, or VMware Fusion.
The hypervisor will run on top of the infrastructure we provide. It could be a server or a local desktop or laptop computer.
But, if you look into the container section, it also have the same 3 applications as the virtual machines. But, here we don’t need to install any local operating system for them.
The containers will run directly on top of Docker engine. The Docker engine is installed on top of host operating system and the operating system will run on top of the infrastructure. The host operating system can be either Windows or Linux.
Let’s see a few of the pros and cons of using virtual machine.
Larger in size
As we all know, virtual machines have their own operating system installed for each instance of virtual machines.
They will consume more resources because of their operating system.
Cost
Cost may also increase since we need to purchase operating system for each virtual machine.
We may need to purchase some other applications such as hypervisors with their own licenses to run the virtual machines.
More Effort
We may need to put more effort for the periodic updates of each virtual machines operating system and other applications installed on each virtual machines.
We need to take necessary steps to secure each of our virtual machines.
Slower Startup
Virtual machines will take more time for booting than container.
Some of advantages of using virtaual machines are mentioned below
Easiness to run traditional application
It is easy to run a traditional application without any modification on virtual machines.
But, in the case of container, we need to containerize the application to run it as container.
For traditional applications, it may have more dependencies with the environment or operating system level areas such as the registry.
For such applications, we need to modify the application first to containerize it.
Strong Isolation
Since every virtual machine has its own operating systems, each VM is strongly isolated from the host operating system.
More mature ecosystem
Virtual machines are used for a long and more mature ecosystem than containerization technology.
By using Virtual machines, we can use the features such as resource scheduling, storage migration, high availability, etc that are available in most of the hypervisors.
Summary
In this article, I tried to explain about the pros and cons of virtual machines and containers.
Containers are not going to replace virtual machines completely as both have their own strengths and weaknesses.