It begins with a hardware infrastructure. both virtual machine and containers are there to utilise the hardware efficiently and provide isolation. But they are different and they serve different purpose. Lets understand virtual machine and docker container first,
Virtual Machine (VM)
Lets understand this from bottom up,
Hardware infrastructure could be a laptop, a server in a data center, or a server hosted in any cloud platforms like from google cloud(GCP) or amazon web services(AWS).
There will be an operating system like linux, macos or windows installed on this infrastructure and It is labeled as host operating system.
Hypervisor is used to create and run virtual machines. Each virtual machine is like a virtual computer packaged into a single file. There are different types of hypervisors available. Some of the popular hypervisors are KVM for Linux, HyperKit for MacOS and, Hyper V for Windows. And another type hypervisors are VirtualBox and VMWare.
Each virtual machine has its own operating system which also then contains the libraries and dependencies required for the application to run. For example you would need database drivers and programming languages like python, ruby, node js installed and libraries like python packages, ruby gems or npm packages.
Finally we have our application source code which is inside the guest operating system for isolation from other applications.
Container / Docker Container
what is a virtual machine what it does?
As you see, from bottom up both Infrastructure and Host operating system are same.
But instead of hypervisor we have container engine. Docker daemon,
Docker daemon communicates with the host operating system for sharing resources and it ensures that also containers are in isolation.
Containers will have their libs and dependencies packaged inside. So without the guest operating system a lot of storage and memory are free which can be utilised further.
Difference between VM and Container
Both Virtual machine and Containers have their own purpose. Containers does not intend to replace virtual machines. Containers are not virtual machine.
Virtual machine comes with a heavy baggage because an entire operating system needs to installed for each application.
Virtual machines are very good at isolating system resources and entire working environments. For example, for a web hosting company you would most likely to use virtual machines to separate each customer.
- Hardware is virtualised.
- Each virtual machine has its own operating system.
- VMs share hardware resources.
- Each VM workload needs a complete OS.
- Used to isolate entire system.
- Statup time is expensive since an entire OS needs to bootup for the application to start.
- Slow startup time when compared to containers.
- Operating system is virtualised
- Docker container is just a set of processes that are isolated from the other processes in the operating system.
- It is run from a image which contains all the lib and dependencies to support the processes.
- Each containers share host os kernel.
- Multiple workloads can be run with one OS.
- Does not require hypervisor
- Fast startup time.