Docker containers vs Virtual machines


I use to think docker containers as a lightweight trimmed down virtual machines, and the comparison made sense because, in the initial marketing of docker, it was compared every time to the virtual machine, for example, docker takes less time to spin up than VM, etc.
But docker container is not virtual machines.

Let's do a side by side comparison of the docker container and virtual machines.

Virtual machines:
Virtual machines (VMs) are an abstraction of physical hardware turning one server into many servers. The hypervisor allows multiple VMs to run on a single machine. Each VM includes a full copy of an operating system, the application, necessary binaries and libraries - taking up tens of GBs. VMs can also be slow to boot.



Virtual machine Architecture:
Let's assume there are amounts of layers,and when these layers are attached, they form a virtual machine.
The bottom-most layer of the virtual machine infrastructure is mostly the hardware of the virtual machine.
This hardware layer is mostly the pool of the required hardware to run the virtual machine consisting of mainly Ram, the memory of the users type it can be SSD(mainly its SSD) or even low-performance HDD, CPU, etc.
Above this layer, there runs a Host OS(mainly Linux) and sometimes Windows. Above this, there exist a layer know as Hypervisor Layer. There are two types of hypervisor layers the one which runs over the hardware layer mainly which is used in the data centers and the one which runs above the operating system which is used in the programs such as VMware or VirtualBox.
Above this Hypervisor layer, there runs the block of Guest OS imagine if you want to run three different types of Applications in complete isolation to each other, then you will need to spin up three separate VM. The Hypervisor directly controls these three VMS.

But now imagine that the three VM had their OS it can be Linux or windows, but for now, we will believe they had Linux operating systems, so if we say that each os roughly is about 700mb. We have Tspin up three VM's, then these three VM's have occupied approximately 2.1GB of storage on our operating system, and on top of that, each Guest Os will require its own set of Bin/Library to lay the groundwork to run you the app. It can be Python Dependencies, Node modules, etc.
And now, finally, we have our Application layer on top of this, which will typically be the source code for the app which you have built.

What is a Container?
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 userspace. 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.




Docker Container Architecture
Docker is not something magical, so it will need some base hardware over which it can run. So the first layer(Hardware Layer) is common to the Virtual machine layer that in infrastructure.
Over this, there is a Host Os. It can be any operating system capable of running docker. Docker supports all the major Linux distribution, and there are ways to run Docker on a Windows machine and a Mac.
Now for the third layer, something is interesting here. The Docker Daemon replaces this layer, which was Hypervisor Layer in the virtual machine architecture. It's a service that runs in the background which is responsible o run the docker contianer.
Then the Bin/Libray resides in a container for the app, and there is source code for the app. The docker daemon manages all this layer of container.
Hence eliminating the need of Guest Os and we can save the amount of memory that where occupied by the Guest Os and also save the load that was being put on the machine while running those VM's.
Here each app is isolated with each other as it has been hosted in different contianer while still being on the same host os.
Ads go here

Comments

Archive

Contact Form

Send