Introduction to Docker VM VS Docker Containers(PART 2)

This Tutorial is the continuation of a series on Docker. In Part 1 of the Tutorial, I covered the importance of Docker, docker containers, docker architecture, and why we need to use docker. In this part of the tutorial, I’ll be giving a brief comparison of Virtual Machines and Docker Containers.

This part of the tutorial will cover the following: –

  1. An overview of VM (Virtual machine)
  2. Primary Usage and advantage of VMs
  3. Problems we face while creating and using VMs
  4. How does Docker Containers help us avoid these problems?
  5. Advantages of Docker Containers over VM

1. An overview of VM (Virtual machine)

(i) The very first question could be, why do we need a VM at all? Let’s think of a scenario where you have two applications, and both applications have different requirements to run. Let’s say one application needs Linux OS to run smoothly and the other application may need windows to run.

The solution could be to run them on different computers having Linux and Windows. Right? So, are we going to purchase two different computers just because two applications need different operating systems to run? Obviously no. This is where Virtual Machines come into the spotlight.

Virtual Machine can run multiple operating system environments on a single physical computer, saving physical space, time, and management costs. Virtual machines help us using multiple Operating Systems on same computer instead of migrating to a new operating system permanently.

(ii) We use hypervisors like Virtual Box to create and run Virtual Machines. A hypervisor is a type of computer software, that creates and runs virtual machines. A computer on which a hypervisor runs one or more virtual machines is called a host machine, and each virtual machine is called a guest machine. A hypervisor allows one host computer to support multiple guest VMs by virtually sharing its resources, such as memory and processing.

2. Primary Usage and advantage of VMs

A virtual Machine is an abstraction of a computer ( physical hardware). This abstraction allows a single machine to act like multiple machines working independently.

For example, If we have a computer with 16 GB RAM and 1TB storage. We can create 2 independent machines having 8GB RAM and 500GB storage. One would be a host machine, while the other would be a virtual machine or an abstraction. Both can run different operating systems and serve our purpose to provide isolated environments for our applications.

3. Problems we face while creating and using VMs

  • There are infrastructure requirements to run Virtual Machines.
  • If we use multiple VMs on one physical system, it can slow down the whole system and can result in unstable performance of the host machine as well.
  • VMs are less efficient and slower than physical machines.

Here is another reason, which makes us consider some other method to have an isolated environment for any application.

What if we need to run multiple applications in isolated environments, let’s say 20 applications? We can not create 20 Virtual Machines for all of them.

4. How do Docker Containers help us avoid these problems?

Docker Containers are lightweight special processes and don’t need a separate OS ( Operating System ) like Virtual Machines or dedicated slices of hardware including cores of CPU and some specific chunk of RAM etc. Docker provides isolated environments in the form of Docker Containers for your applications. You can create multiple containers for all of your applications depending on the hardware resources availability.

Docker Container is just like any other process running on your Computer. These Containers on a host machine share the OS running on that machine. More specifically, they share the Kernel of the Operating System running on that host machine. Detail has been covered in part 1 of this series.

5. Advantages of Docker Containers over VM

  • Docker containers are just like other processes running on your computer and do not require a hypervisor. Which makes them lightweight.
  • Docker containers are much smaller than VMs and require far fewer resources, which makes them fast.
  • If we need too many isolated environments to run multiple applications, we can create multiple Docker Containers (let’s say 20 or 30), but we can not create that many VMs due to infrastructure requirements.
  • Creating a Docker Container may just take seconds. While setting up a Virtual Machine can itself be a hassle? ( You probably already know about that, if you are a programmer 😊).

So, depending on the needs, we should leverage both Virtual Machines and Docker Containers. Both are equally powerful and useful. I hope you liked this tutorial. Stay tuned for further tech-related Blogs.