What Is a Virtual Machine - and When a Container Is the Better Answer
A virtual machine is a complete computer implemented in software: it has its own virtual CPU, its own memory, its own disk, and - this is the part that matters - its own kernel. What is a virtual machine really doing? It is presenting a fake set of hardware convincing enough that an unmodified operating system boots on it and never needs to know it is not alone.
The problem it exists to solve is that one physical machine running one operating system is a terrible unit of allocation. You buy a server sized for peak load, you run one workload on it, and you waste most of the capacity. Worse, two workloads on the same OS can see each other's processes, fight over the same kernel settings, and take each other down.
A VM cuts the machine into slices that cannot see each other, each slice being a thing that boots. That is the whole idea. Everything else - live migration, snapshots, cloud instances - falls out of it.
The cost is that you are now running many kernels instead of one, and you pay for every one of them in memory, boot time, and patching.
| Concept | Virtual Machine (VM) |
|---|---|
| Where it sits | Infrastructure - sits between physical hardware and the guest operating system, managed by a hypervisor |
| In one sentence | A software-emulated computer that runs its own kernel on shared physical hardware, isolated from its neighbours by the hypervisor. |
The 60-Second Answer
A virtual machine is a software-defined computer that boots its own operating system on top of a hypervisor, which divides one physical host into isolated slices.
The one problem it solves: hard isolation between workloads. Separate kernels mean a neighbour cannot read your memory, exhaust your file descriptors, or require the same kernel version you do.
The one cost it adds: a full OS per workload. Hundreds of megabytes of resident memory, seconds-to-minutes of boot time, and one more thing to patch - multiplied by instance count.
In the vm vs container decision: choose a VM when you need a different kernel or a trust boundary you can defend to an auditor. Choose a container when the workloads are yours and share a kernel happily.
How It Actually Works
The mechanism, step by step
- 1. The hypervisor owns the real hardware and hands out fake hardware
- 2. The CPU does most of the isolation in hardware
- 3. Memory is translated twice
- 4. Each VM boots its own kernel - this is the real dividing line
- 5. Virtual devices are a contract, and the fast ones are negotiated
- 6. The whole machine is a file, which is why snapshots and migration work
- 7. Isolation is strong but the hardware underneath is still shared
1. The hypervisor owns the real hardware and hands out fake hardware
One layer below the guest OS
The hypervisor is the component that actually talks to the physical CPU, memory controller, and devices. It presents each guest with a synthetic machine: a set of virtual CPUs, a memory range that looks like physical RAM, and virtual devices for disk and network.
The guest OS boots against that synthetic machine exactly as it would against metal - it probes for devices, finds them, loads drivers. The deception is at the hardware interface, which is why an unmodified OS image works.
Hypervisors come in two broad shapes. A type 1 hypervisor runs directly on the hardware and is essentially a minimal kernel of its own; a type 2 hypervisor runs as a process inside a normal host OS. Cloud providers run type 1. Your laptop's desktop virtualization is usually type 2.
⚠️ In production — The split is less clean than the diagram suggests. Some type 1 hypervisors delegate device emulation to a privileged helper process, so a crash in that helper can take a guest down even though the hypervisor itself is fine. When you are debugging a guest hang, the hypervisor is not one thing - find out which part owns the device you are stuck on.
2. The CPU does most of the isolation in hardware
Virtualization extensions, not emulation
Modern VMs are fast because the processor cooperates. CPU virtualization extensions add a mode where guest code runs natively on a real core, at real speed, until it does something that needs supervision - touching a control register, accessing a device, handling certain interrupts.
At that point the CPU traps out to the hypervisor. This is a VM exit: the guest stops, the hypervisor handles the event, and control returns. Ordinary arithmetic, branches, and memory loads inside the guest are not intercepted at all.
This is the difference between virtualization and emulation. An emulator interprets or translates every guest instruction and is orders of magnitude slower. A hardware-assisted VM runs guest instructions on the metal and only pays on the boundary.
⚠️ In production — VM exits are where your mystery latency lives. A workload that does lots of small I/O, or hammers timers, crosses that boundary constantly and the exit cost dominates. The fix is almost never more vCPUs - it is batching the work, or using paravirtual drivers that were written to minimise exits. CPU-bound compute inside a VM looks nearly native; syscall-and-interrupt-heavy work does not.
3. Memory is translated twice
Guest physical is not host physical
Inside the guest, the OS maintains page tables mapping guest virtual addresses to what it believes is physical memory. But guest physical memory is itself a fiction the hypervisor maintains, backed by scattered pages of real host RAM.
So there are two translation layers stacked: guest virtual to guest physical, then guest physical to host physical. CPUs with nested paging support do both in hardware, which is why this is tolerable rather than catastrophic.
The hypervisor can be clever here. It can over-commit - allocate more guest memory in total than the host physically has - and lean on the fact that most guests do not touch all their pages. It can deduplicate identical pages across guests.
⚠️ In production — Over-commit is a loaded gun. It works beautifully until several guests expand their working sets at once, and then the host starts swapping guest memory to disk. The guest OS has no idea this is happening - it thinks it is touching RAM - so its own scheduler makes terrible decisions. The symptom is a guest that is inexplicably slow with no visible load. You can only see it from the host.
4. Each VM boots its own kernel - this is the real dividing line
Where vm vs container is decided
A VM contains an entire operating system: bootloader, kernel, init system, system daemons, package manager, the lot. It boots the way a physical machine boots.
A container shares the host kernel. It is a set of processes with their own filesystem view and their own namespaced view of process IDs, network interfaces, and mounts - but when container code makes a system call, the host kernel services it directly.
That single difference generates every other difference in the vm vs container comparison. A VM can run a different OS or kernel version than its host; a container cannot. A VM's memory floor is a kernel plus userland; a container's is just its processes. A VM boots in seconds or longer; a container starts about as fast as a process.
⚠️ In production — Teams routinely pick a VM for "isolation" when they mean "my dependencies conflict with the other team's". Dependency conflict is a filesystem problem and a container solves it at a fraction of the cost. Reach for a VM when you need a kernel boundary or a different kernel - not when you need a different version of a shared library.
5. Virtual devices are a contract, and the fast ones are negotiated
Emulated versus paravirtual I/O
The guest needs a disk and a NIC. The hypervisor can emulate a real device register-for-register, which works with any OS driver but is slow - every register poke is a VM exit.
The faster path is paravirtual devices. The guest loads a driver that knows it is in a VM and talks to the hypervisor through a shared-memory ring buffer, submitting batches of requests and getting batched completions. Far fewer boundary crossings for the same work.
Faster still is device passthrough, where the hypervisor assigns a physical device directly to one guest. Near-native performance, at the price of that device no longer being shareable or the VM easily movable.
# Inside a Linux guest, paravirtual block devices usually
# show up under a distinct name - a quick sanity check
# that you are not on the emulated slow path.
lsblk
⚠️ In production — A guest image missing paravirtual drivers still boots - it just silently falls back to emulated devices and runs several times slower on I/O. This is a classic migration failure: you lift an old image into a new environment, it comes up fine, and nobody understands why throughput collapsed. Check which driver the guest actually bound before you start tuning anything else.
6. The whole machine is a file, which is why snapshots and migration work
State you can copy
A VM's state is just data the hypervisor holds: a disk image, a memory image, and CPU register contents. Nothing is intrinsically tied to the host.
So you can snapshot it - freeze that state and roll back to it later. And you can live migrate it - copy memory pages to another host while the guest keeps running, iterate over the pages that changed, then pause briefly, ship the last delta plus CPU state, and resume on the new host.
This is the operational superpower of VMs and it has no clean container equivalent. It is how cloud providers patch hypervisors underneath running instances, and how a host can be drained before maintenance.
⚠️ In production — Snapshots are not backups and treating them as such ends badly. They commonly live on the same storage as the disk they protect, they accumulate chains that degrade write performance, and a snapshot of a running database captures a crash-consistent image, not a clean one - you are relying on the database's own crash recovery to be correct. Also: live migration pauses the guest at the end. Short, but not zero. Anything with a hard sub-millisecond deadline will notice.
7. Isolation is strong but the hardware underneath is still shared
The boundary and its leaks
The hypervisor's attack surface is narrow by design - a small interface compared to a full kernel - which is what makes VMs the standard boundary for running untrusted code. Escaping a VM is a serious, rare class of vulnerability.
But the slices share real silicon. Caches, memory bandwidth, and storage queues are common resources, so one greedy neighbour degrades another's performance even with perfect correctness isolation. This is the noisy neighbour problem.
And shared microarchitectural state has been the source of a whole family of side-channel attacks, where a guest infers another guest's data by measuring timing rather than by reading memory it should not have.
⚠️ In production — "Isolated" means different things to a security reviewer and to a latency engineer. Your VM boundary can be cryptographically sound and your p99 still ruined by whatever is running on the adjacent core. If your workload is latency-sensitive, you need dedicated hosts or pinned cores - the VM abstraction will not give you that by itself, and no amount of guest-side tuning substitutes for it.
## Where You Meet It
- Every cloud compute instance you have ever rented is a VM. You request a size, the provider's hypervisor carves that out of a physical host shared with other tenants, and you get a machine you can SSH into and reboot. The VM boundary is what makes it safe for the provider to put your workload next to a stranger's on the same metal.
- A container platform that runs on cloud infrastructure is running containers inside VMs. The VM supplies the tenant boundary and the kernel; containers inside it supply fast, cheap packaging for the many services one team owns. This is the common answer to vm vs container in practice: both, at different layers, for different jobs.
- A team maintaining software that must run on an older OS release keeps a VM of that environment. The host fleet has moved on; the application has a kernel-level dependency that did not. A container cannot help here, because a container would get the host's kernel.
- Serverless function platforms face a hard problem: they run untrusted code from arbitrary customers, but a VM's boot time is far too long for a request-scoped workload. The response has been lightweight VMs with minimal device models and stripped-down guest kernels - keeping the hypervisor boundary while cutting startup cost dramatically. The tradeoff is a narrow set of supported virtual devices.
- A developer on one OS needs to build and test software for another. A VM on the laptop gives a real instance of the target OS, with its real kernel, instead of a compatibility layer whose differences surface at the worst possible moment.
When You Actually Need It
- You need a different kernel or a different operating system than the host runs - a kernel module, an OS-specific driver, or a legacy platform dependency. Containers are categorically unable to do this.
- You are running code you do not trust, or code from parties who do not trust each other. If a multi-tenant compromise is on your risk register, the hypervisor boundary is the one you can defend in a review.
- A compliance or audit requirement specifies machine-level separation between workloads. The question is settled by whoever signs the audit, and shared-kernel isolation is frequently not accepted.
- You need to move running workloads between physical hosts without stopping them - draining a host for maintenance, rebalancing capacity. Live migration is a VM capability with no direct container equivalent.
- The workload genuinely behaves like a machine rather than a process: it has an init system, cron jobs, multiple interdependent daemons, and expects to manage its own lifecycle. Forcing that shape into a container fights the model the whole way.
- You need to roll an entire environment back to a known state quickly during testing or incident recovery, and reconstructing it from configuration would take hours.
When You Don't
- Your problem is conflicting dependencies between your own services. That is a filesystem-isolation problem and a container solves it with a fraction of the memory and startup cost. A VM per service here means you are patching N kernels to avoid a library version clash.
- You are running fewer than a handful of services on one box and they coexist fine. Run them as processes on the host under your init system, with resource limits if you need them. A hypervisor layer under three cooperating daemons buys you overhead and a second fleet to patch.
- The workload is short-lived or request-scoped. If the unit of work finishes in under a second, a general-purpose VM's boot time dominates everything. Use containers, or a platform built on lightweight VMs that has already solved the startup problem.
- You need maximum performance from one dedicated machine. If the box is yours and runs one workload, the hypervisor is pure cost: VM exits, double translation, device indirection. Run on the metal.
- You are reaching for a VM to get a clean, reproducible build environment. A container image is a better reproducibility artefact - smaller, faster to distribute, and version-controlled as a definition file rather than a multi-gigabyte blob nobody can diff.
- You are adopting VMs because a prior incident was blamed on "not enough isolation" without a diagnosis. Find out what actually crossed the boundary first. If it was CPU or memory contention, resource limits fix it; a VM does not, because the hardware underneath is still shared.
What People Get Wrong
"VMs are slow, so containers are always faster."
CPU-bound work inside a VM runs on real cores at close to native speed, because hardware virtualization only intercepts privileged operations. The VM tax shows up at boundaries: I/O, interrupts, startup time, and memory floor. A compute-heavy job may see almost no difference; a chatty-I/O or rapidly-cycling workload sees a lot. Ask which kind yours is before accepting the generalisation.
"Containers are just lightweight VMs."
They are not the same kind of thing. A VM virtualizes hardware and boots a kernel; a container is a group of host processes with a restricted view of the system, serviced by the host kernel. That is why a container cannot run a different kernel and why a kernel vulnerability is a shared-fate event for every container on the host.
"A snapshot is a backup."
A snapshot is usually a point-in-time reference on the same storage as the live disk, so it does not survive the failure of that storage - and for a running database it is crash-consistent, not application-consistent. It is an excellent undo button for a risky change and a poor disaster recovery plan. You need both, and they are different systems.
"If it is in its own VM, it is isolated."
Isolated in terms of memory and kernel state, yes. Not isolated from cache pressure, memory bandwidth contention, storage queue depth, or microarchitectural side channels - all of which come from sharing physical hardware. Performance isolation requires dedicated capacity, which is a separate purchase and a separate decision.
Why It Was Built This Way
The original constraint was economic and it was brutal: a computer was the most expensive thing an organisation owned, and an operating system assumed it owned the whole machine. You could not run two workloads that each wanted to be in charge. Virtualization was invented to subdivide an asset too valuable to dedicate to one job.
That origin fixed the shape of the abstraction. The interface being virtualized is the hardware interface, not the system call interface. This was not an aesthetic choice - it was the only one that let unmodified operating systems run unchanged. If you had virtualized at the syscall layer instead, every guest OS would have needed porting, and the whole point was to avoid touching the software you already had.
What got traded away was density and startup latency, and the bill is paid in duplicated kernels. Every VM carries a full copy of OS machinery doing work the host is already doing: scheduling, memory management, page cache, device drivers. The guest's scheduler makes decisions without knowing it is being scheduled; its page cache caches data the host is also caching. This redundancy is not a bug to be optimised away - it is the direct consequence of choosing an interface low enough that the guest cannot tell it is a guest.
Containers are the other branch of that same decision tree. They virtualize at the kernel's own abstractions - namespaces for what a process can see, control groups for what it can consume - which is why they are cheap and why they cannot cross a kernel boundary. Neither is the successor to the other. The industry's settled answer is to nest them: VMs where the trust boundary must be hardware-deep, containers inside for packaging and density. When you are weighing vm vs container, you are really choosing which interface you want to lie about, and each lie has a known price.
Related Briefs
What to Read Next
- what is a hypervisor
- containers vs virtual machines performance
- what is kvm virtualization
The decision rule is narrow and worth memorising: you need a virtual machine when you need a different kernel, or a boundary you can defend to someone who audits you. Everything else that gets called "isolation" - dependency conflicts, resource limits, reproducible environments - has a cheaper answer. If you cannot name which of those two reasons applies, you are probably about to pay for a fleet of kernels you did not need.
댓글
댓글 쓰기