Signup/Sign In

Container vs. Virtual Machine

Docker containers and virtual machines are absolutely different in their architecture but are often confused to be similar. In this tutorial, we will see the difference between a docker container and virtual machines by understanding their architecture and how they work on top of the host operating system.

We have already covered how docker container works, utilizing the same OS Kernel with resource limitation done using the cgroups and namespaces to decide the boundaries of a docker container. Let's dig a bit deeper to understand what all this means.

Docker Containers

In the diagram below, we have the architecture of a basic Docker setup running on a host machine with 3 containers running on top of it in which 3 different applications are running.

Docker container architecture on host machine

Docker Engine utilises the Host OS Kernel(Linux) for communicating with the underlying hardware. All the containers running on docker shares the same Host OS Kernel, hence they do not have to set up their own OS Kernel which makes them lightweight.

Also, inside a docker container, only a single application process should be run, as recommended by docker, and the container should have its required libraries and dependencies.

Each and every container running on the docker is completely isolated from each other.

Containers run natively on Linux and if you want to setup it on Windows operating system, the windows docker application will install a Linux virtual machine for itself.

Virtual Machine

Unlike a container, a virtual machine doesn't utilize the host OS Kernel, on the contrary, it installs its own guest Operating system. The virtual machine also emulates the hardware layer, which virtually utilizes the host resources through a hypervisor.

This makes the virtual machine heavy and slow.

Virtual machine architecture

One virtual machine is completely isolated from another virtual machine. In the case of the virtual machine, you can even install different operating systems on different virtual machines.

Container vs. Virtual Machine

Now that you have understood the difference between containers and virtual machine, let's see the main differences between both:

Container Virtual Machine
Smaller in size Larger in size, generally in GB.
Bootup is fast. Bootup is slow.

Share resources managed via cgroups by OS Kernel.

It also shares the same OS Kernel.

Complete isolation from each other.

Docker is not meant for virtualizing an operating system with its Kernel, but it is made to package an application in a frozen app state which can be run inside a container.

On a large scale infrastructure setup, we have virtual machines running OS installed on server racks on top of which docker is run with its containers running individual services.

In the next tutorial, we will learn how to install docker locally on different operating systems.



About the author:
I like writing content about C/C++, DBMS, Java, Docker, general How-tos, Linux, PHP, Java, Go lang, Cloud, and Web development. I have 10 years of diverse experience in software development. Founder @ Studytonight