Infrastructure and deployment
What is a Virtual Machine?
Definition
A virtual machine is a software-emulated computer that runs its own complete operating system on top of a hypervisor, isolated from the host and from other VMs.
Also known as: VM
Virtual Machine in more detail
A hypervisor divides one physical machine's CPU, memory, disk and network into virtual ones and presents each as if it were real hardware. The guest operating system boots normally and has no need to know it is virtual. Type 1 hypervisors such as KVM, Xen, ESXi and Hyper-V run directly on the hardware and are what clouds are built from; type 2 hypervisors such as VirtualBox and VMware Workstation run as an application on a desktop operating system.
The boundary is strong precisely because the guest has its own kernel. Escaping to the host means defeating the hypervisor, a much smaller and more hardened surface than a shared kernel, which is why VMs remain the unit of isolation between different customers in public clouds. It also means a VM can run a completely different operating system from the host — Windows on a Linux host, or vice versa.
The price is weight. Every VM carries a full operating system, so it takes gigabytes of disk, hundreds of megabytes of memory before your application starts, and seconds to boot rather than milliseconds. That is the core trade against containers, and in practice the two are layered rather than opposed: cloud instances are VMs, and the containers people deploy run inside them.
Virtual Machine example
Virtual machines Containers
app app
libs libs
GUEST OS (full kernel) <-> (shares the host kernel)
hypervisor container runtime
host OS host OS
hardware hardware
boot: seconds boot: milliseconds
size: gigabytes size: megabytes
isolation: strong isolation: process-level
can run a different OS same kernel only
Nesting is the normal case in the cloud:
EC2 instance (a VM) -> Docker -> your containerVirtual Machine — common questions
- What is a hypervisor?
- The software layer that creates and runs virtual machines, allocating real CPU, memory and devices among them. Type 1 runs on bare metal and powers cloud providers; type 2 runs as an application inside a desktop operating system.
- Are VMs obsolete now that containers exist?
- No. They provide stronger isolation, can run different operating systems, and are what cloud instances actually are. Most container workloads run inside VMs, so the two are layers rather than competitors.
- Why are containers faster to start than VMs?
- Because a container starts a process against an already-running kernel, while a VM must boot an entire operating system first. That difference is milliseconds against seconds, and megabytes against gigabytes.
Keep reading
Every definition in the set is indexed A-Z in the developer glossary, and the cheat sheets cover the syntax once you know what you are looking for.
Browse the A-Z glossary