DEV Community

Cover image for Docker vs Virtual Machine Analogy
Atul Kushwaha
Atul Kushwaha

Posted on

Docker vs Virtual Machine Analogy


Hey guys, I have just started learning Docker, so I wanted to share this analogy that came to my mind. I believe analogies make things much clearer and easier to remember than anything else ever could.

Overview of Virtual Machines


  • Let's talk about VMs first. Virtual Machines use something called a hypervisor on top of hardware.
  • A Hypervisor is a piece of software that manages hardware resources across virtual machines. One may think of a Hypervisor as an "HR manager" πŸ˜‚.
  • On top of the hypervisor, we have the virtual machine, each with its own underlying OS running applications. This is great if we want to run different services/applications on different operating systems, but it also comes with disadvantages such as:
    • Consuming a lot of resources, as every virtual machine has to run a separate operating system.
    • Slow startup time.

Overview of Docker


  • Now, Docker has an operating system on top of which we have the Docker engine.
  • The container engine is what unpacks the container files and hands them off to the operating system kernel.
  • On top of the container engine, we have applications that use the underlying operating system available on the server. Containers only contain the necessary files to run a specific application, which makes them:
    • Very lightweight.
    • Very fast and compact. Whereas VMs use a separate operating system.
  • Now, with advantages come some disadvantages, which are:
    • If the OS running on the server is Linux, then applications must also be Linux-based. They can be of different distros as Docker uses the underlying operating system's kernel.

By the way, this is what makes Linux extremely fast, as instead of using multiple OSes, it uses the kernel of a single OS to manage and isolate different applications.

The Analogy

  • Now that we have an overview of how both technologies work, here's the analogy:
  • One may think of a Virtual Machine as a shop that specializes in giving services of a single product category (like an electronic shop or furniture store). Imagine if I had to sell dairy products from a pharmacy; I can't do that, right? I would have to build a new shop to sell dairy products.
  • Now, enter Docker. We can see it as a shopping complex, with different shops running under the same building (different applications running on the same underlying operating system). I may open as many different shops as I wish (subjected to availability of hardware resources).

Follow for more, As I learn more about Docker I'll post more Analogies

Top comments (0)