when it comes to cloud infra, the virtual machine has been the go-to standart for many of its advantage. However Docker come with a new idea of virtual machine that was more lightweight, economical, and scalable.
docker is a container based lets you develop distributed applications. so for today article we will go through the difference between virtual machine and docker containers.
What is a Virtual Machine?
A virtual machine is a system which acts exactly like a computer.
In simple terms, it makes it possible to run what appears to be on many separate computers on hardware, that is one computer. Each virtual machine requires its underlying operating system, and then the hardware is virtualized.
What is Docker?
Docker is a tool that uses containers to make creation, deployment, and running of application a lot easier. It binds application and its dependencies inside a container.
Docker vs. VM
Infrastructure
The operating system support of Virtual machine and Docker container is very different. From the image above, you can see each virtual machine has its guest operating system above the host operating system, which makes virtual machines heavy. While on the other hand, Docker containers share the host operating system, and that is why they are lightweight.
Sharing the host operating system between the containers make them very light and helps them to boot up in just a few seconds. Hence, the overhead to manage the container system is very low compared to that of virtual machines.
The docker containers are suited for situations where you want to run multiple applications over a single operating system kernel. But if you have applications or servers that need to run on different operating system flavors, then virtual machines are required.
Security
The virtual machine does no share operating system, and there is strong isolation in the host kernel. Hence, they are more secure as compared to Containers. A container have a lot of security risks, and vulnerabilities as the containers have shared host kernel.
Also, since docker resources are shared and not namespaced, an attacker can exploit all the containers in a cluster if he/she gets access to even one container. In a virtual machine, you don’t get direct access to the resources, and hypervisor is there to restrict the usage of resources in a VM.
Portability
Docker containers are easily portable because they do not have separate operating systems. A container can be ported to a different OS, and it can start immediately. On the other hand, virtual machines have separate OS, so porting a virtual machine is difficult as compared to containers, and it also takes a lot of time to port a virtual machine because of its size.
For development purposes where the applications must be developed and tested in different platforms, Docker containers are the ideal choice.