Skip to main content

Command Palette

Search for a command to run...

VM vs Containers: What Every Backend Developer Should Know

Updated
4 min read
VM vs Containers: What Every Backend Developer Should Know
S

I'm Saroj Bist, a self-taught web developer, learning and building with the MERN stack. I started with front-end tools like ReactJS and Tailwind CSS, and slowly stepped into full-stack development, working on real projects and solving real problems. This blog is where I share what I’m learning — from small bugs to full project insights — in a way that helps both me and anyone on a similar path.

What is a Virtual Machine (VM)?

A Virtual Machine (VM) is a software-based computer that runs inside our physical machine. It allows us to run multiple independent systems on a single computer.

Even though it is virtual, it behaves like a real system with its own operating system, virtual CPU, memory (RAM), and storage. Each VM works independently, just like a separate computer.

How a Virtual Machine Works

A Virtual Machine works using a special layer called a hypervisor, which acts as a manager between the hardware and the virtual machines.

It has following Components:

  1. Host Machine (Physical System)
    Our real computer (CPU, RAM, Disk)

  2. Hypervisor (Manager Layer)
    Creates and manages virtual machines Allocates resources

  3. Guest Machines (VMs)
    Each VM runs its own OS Applications run inside it

Hypervisor

A Hypervisor is the core component that makes virtualization possible.

It:

  • Allocates CPU, RAM, Storage

  • Runs multiple VMs

  • Keeps VMs isolated

Without hypervisor, VMs cannot run.

Types of Hypervisors

1. Type 1 (Bare Metal)

A Type 1 hypervisor runs directly on the physical hardware without any host operating system in between. This means it has direct access to system resources like CPU, memory, and storage, making it highly efficient and fast.

Because there is no extra OS layer, it provides better performance and stronger isolation. That’s why Type 1 hypervisors are commonly used in production environments and data centers.

Examples include VMware ESXi and Microsoft Hyper-V.

2. Type 2 (Hosted)

A Type 2 hypervisor runs on top of an existing operating system, just like a normal application. It depends on the host OS to access hardware resources.

Because of this extra layer, it is slightly slower compared to Type 1, but it is much easier to install and use. This makes it ideal for development, testing, and learning purposes.

Examples include VirtualBox and VMware Workstation.

What is a Container

A container is a packaged application with everything it needs to run, except the operating system where it shares the host OS kernel.

What goes inside a container?

A container includes:

  • Our code

  • Runtime environment for our code

  • Required libraries

  • Config

Everything needed to run the app

Important: What is NOT inside?

  • No full OS

It uses host OS kernel

Feature VM Container
OS Full OS per VM Shared host kernel
Size Heavy (GBs) Lightweight (MBs)
Boot time Minutes Seconds
Isolation Strong Moderate
Performance Slower Near-native

Docker on Windows — Why Docker Desktop and WSL?

Docker was originally built for Linux because containers depend on Linux kernel features like namespaces and cgroups. These features are what allow containers to run as isolated processes. The problem is that Windows does not provide these same kernel capabilities, which means Docker cannot run natively on Windows in the same way it does on Linux.

To solve this, Windows uses something called Windows Subsystem for Linux (WSL). WSL allows us to run a real Linux environment inside our Windows machine. With WSL 2, Microsoft introduced a lightweight virtualized Linux kernel, which makes it fully compatible with Docker. This is the key piece that enables containers to work properly on Windows.

Docker Engine is NOT running on Windows
It is running inside Linux (WSL)

What is Docker Desktop?

Docker Desktop is a tool that:

  • Installs Docker easily

  • Manages containers

  • Provides GUI + CLI support

  • Connects Docker with WSL

How we can run Linux on Windows easily but not the Windows on Linux?

We can run Linux on Windows easily because tools like WSL provide a Linux kernel inside Windows.
But running Windows on Linux is not easy because there is no equivalent lightweight way to provide a Windows kernel inside Linux.

Can we run Windows-based Docker images on Windows if Docker Desktop uses WSL?

Yes, we can run Windows-based Docker images on Windows, but not when Docker is using WSL (Linux mode).

Docker Desktop has two modes:

  • Linux Containers Mode (WSL)
    In this mode, Docker uses the Linux kernel provided by
    Windows Subsystem for Linux.
    So only Linux-based images can run here.
    Windows images will NOT work because they require a Windows kernel.

  • Windows Containers Mode
    In this mode, Docker uses the Windows kernel directly.
    So we can run Windows-based images here.