We have talked about how Virtual Machines or VMs have made life easier for development teams as one can just onboard a VM from a cloud service provider and deploy the application on it. One major challenge with Virtual machines is that they are heavyweight.
Let’s take a look at how virtual machines are designed to work
Rather than directly installing an operating system, there is a layer of hypervisor that abstracts underlying hardware. This allows separation of the OS layer, and one can independently install any OS without worrying about the infrastructure layer. As we can see each VM is a completely independent system in itself where an OS is managing hardware and software resources. Now the problem here is that OS itself is a heavy piece of Software and normally needs a good amount of processing capabilities in terms of CPU, RAM, and Storage.
To understand the scope of the problem, let us say we need to deploy three services for an application, a product detail service, a search service, and a shopping cart service. To keep them independently maintainable and scalable, it makes sense for us to deploy them separately. So we can take thee different set of VMs and deploy services. As we can see, that an additional burden we need to carry is each VM has its own OS that is eating up our compute resources.
The solution here provided by containers is to move abstraction one layer above the OS. That is, instead of directly installing our services or application servers on OS, we create containers above the OS layer, which gives us the flexibility to deploy multiple containers on a single OS.
The image below should clarify the though process.
The docker layer here represents the container engine. Docker is a technology, created by the namesake company which helps us implement the container-based deployments for our application. Rather than re-inventing the wheel, let’s take a look at definition provided by https://www.docker.com/
Containers are an abstraction at the app layer that packages code and dependencies together. Multiple containers can run on the same machine and share the OS kernel with other containers, each running as isolated processes in user space. Containers take up less space than VMs (container images are typically tens of MBs in size), can handle more applications and require fewer VMs and Operating systems.
Coming back to our example of three services, now instead of creating three machines we can generate three containers on single machine helping us use our resources in optimised manner.
One thought on “Containers vs VM”