Difference between Docker and Virtual Machine.

Dhathri Vupparapalli
4 min readJul 10, 2021

Docker container vs Virtual Machine (VM).

Before seeing how Docker and VM are working at OS level, Let’s see how OS is made of.

Hardware of the system will be at the bottom on top of that kernel and at the top Applications are present. This is the overview of OS layout.
overview architecture to see on which layer applications run.

It has two layers. Kernel is the part that communicates with hardware components like CPU, memory etc. Application layer runs on top of the OS kernel layer. For example, Linux OS has a lot of distributions like Ubuntu, Linux mint etc., all these distributions look different in their interfaces, file systems and their UI also looks different. All these distributions use the same Linux kernel, but implement different applications on top.

What is Docker?

Docker uses host OS. On top of that we have a docker runtime environment. On top we have applications running on docker
Architecture of docker at OS level

Docker is a tool which uses containers to virtualize the applications at OS level. Instead of downloading applications into our system, docker uses containers to virtualize those applications. Containers bind the applications along with the dependencies needed to make these applications run a lot more easier.

Containers is an abstraction at application level. Containers use host OS. Multiple containers can run on the same machine and they share kernels with other containers. Size of the container is MB which makes it easier to start and run.

Key Takeaways:

  1. Containers virtualize the applications layer.
  2. Containers don’t have their own virtual OS. It uses a host OS.
  3. Size of the container is in Megabytes, which makes the application run faster.

What is a Virtual Machine?

Infrastructure layer is the bottom most layer and on top of that there will be a hypervisor which is responsible for managing all the VMs. VMs don’t use host OS. Each VM has its own OS.
Architecture of a VM

Virtual Machines work exactly like a computer. Virtual Machines doesn’t use host OS, instead Virtual Machines uses its own OS. There will be a hypervisor on top of Infrastructure(Hardware) which is responsible for running multiple VMs on a single system. These VMs virtually share the host hardware and use Virtual RAM, network and Hard Disk Drive according to usage limited to each VM. Each Virtual Machine has its own OS, applications, libraries which results in more size (in GB). VMs can also be slow to start and run.

Key Takeaways:

  1. Virtual Machines virtualizes both OS and applications layers.
  2. VMs have their own OS.
  3. Size of the VM will be in GB, which makes the VM slow to start and run.

Docker vs Virtual Machine

The following are the major differences between Docker and VMs.

1. Size

Docker images are smaller than the VMs. Docker containers are light weight images because of this reason. Docker saves us from handling a lot of virtual resources, OS maintenance etc.

2. Speed

Since the size of Docker containers is much smaller than VMs, Docker containers start and run much faster than VMs.

3. Compatibility

VM of any OS can run on any OS host. Let’s say you have a windows OS with kernel and applications and now you want to run a Linux based OS on the windows host. The problem here is that Linux based docker image might not be compatible with windows kernel. This is true for Windows versions below 10 and also for older MAC versions. In that case we need to install a technological Docker desktop which abstracts kernel and makes it possible for a host to run different docker images. Whereas VMs don’t have such compatibility issues because they have their own OS.

Conclusion

Docker containers and VMs have their own benefits and drawbacks. The final decision on using either Docker or VM depends on specific needs on the project., but there are some specific things to be considered while making a decision.

  1. You can choose VMs to run applications which require all the resources and functionality of an operating system and you have multiple applications to run on servers.
  2. Containers are a better choice when your biggest priority is maximizing the number of applications running on a minimal number of servers.

--

--

Responses (1)