Let's see the following differences between virtual machines and containers:
Virtual machines |
Containers |
Virtual machines include the applications, the required dependencies, and a full guest operating system |
Containers include the applications and the required dependencies, and share operating systems and underlying infrastructure |
Each virtual machine has its own guest operating system; because of this, it requires more resources |
Because containers share resources, they require fewer resource, the minimal kernel of the operating system present for each container |
The hypervisor manages VMs, environments |
The container engine manages containers |
You have to add specific resources for scaling |
You can scale out containers by creating another container of an image |
Fewer virtual machines can be created for the same hardware and resources |
More containers can be created for the same hardware and resources |
Virtual machines are virtualizing the underlying hardware |
Containers are virtualizing the underlying operating system |
A VM can take up several GB depending on guest OS |
Containers don't require that many GB, because they share resources, they merely use dozens of MB |
Virtual machines are generally more suitable for monolithic applications with high-security concerns |
Containers are generally more suitable for microservice-based applications, or other cloud-native applications, where security is not the major concern |
As we have seen in the previous table, VMs and containers cannot replace each other. So, we can choose according to application requirements and application architecture.