Docker Containers vs Virtual Machines

Docker Containers vs Virtual Machines

We don't kill an ant with a sword

Introduction

When I started learning docker, the first thing that made me roll my head was, when we can use virtual machines to solve the exact same problem that docker does then why do we even have docker in the first place. Silly I didn't understand the core logic behind docker containers and virtual machines.

But now that I do, I would like to pen down the differences between a docker container and a virtual machine so that anyone who is having a similar doubt can get a clear understanding of this.

The whole idea of docker and in fact virtual machines also can be seen as it solves the problem of 'it works only on my machine'.

To understand what a virtual machine (VM) is, let's first take a look at what a hypervisor means.

What is a hypervisor?

  • A hypervisor, also known as a virtual machine monitor or VMM, is software that creates and runs virtual machines (VMs).

  • A hypervisor allows one host computer to support multiple guest VMs by virtually sharing its resources, such as memory and processing.

Coming back to virtual machines now.

Virtual Machine Architecture

  • Virtual machines are isolated environments that lie on top of a hypervisor and each virtual machine has its own separate guest OS.

The below diagram will help you frame a clear picture of VMs in your mind.

Virtual Machines.png

As you can see each of the VM boxes run on a separate guest OS. This is what makes Docker containers different than VMs.

Docker Container Architecture

  • In docker also, the containers are isolated but they share the same host OS kernel.

  • Docker engine is used as a runtime environment instead of a hypervisor.

For example, if we have 3 docker containers then we won't be needing 3 separate guest OS for each of the containers. All 3 of them will share the resources of the host OS. This is why docker containers are so lightweight and easily manageable. Where the size of a single VM can be in gigabytes, the size of a docker container performing the same actions as that of the VM would be in megabytes.

The below diagram will help you frame a clear picture of docker containers in your mind.

Docker Containers.png

As you can see, there is no guest OS in the containers. They will share the resources of the host OS which will be mapped to each container by the docker engine.

I hope you all have now got a better understanding of the differences between a docker container and a virtual machine. Thanks for reading.

Feel free to connect with me on LinkedIn.

Cheers! 🤘