How is a container different from a virtual machine?
Take a moment.
Say your answer out loud or write it down first — retrieval is what makes it stick. Reveal when you're ready.
Short answer
A VM virtualizes hardware and boots a full guest OS with its own kernel — heavy, slow to start, one app per VM is wasteful. A container is just an isolated process sharing the host kernel with its own files, so it starts in milliseconds and packs many apps per host. In practice they are combined: VMs provide hosts, containers pack apps onto them.
Detailed explanation
A VM carries an entire operating system: virtual hardware, guest kernel, drivers, and userland. Isolating a single app that way costs gigabytes and minutes. A container uses Linux namespaces (and cgroups) to give one process its own isolated view — filesystem, networking, process IDs — while sharing the host kernel, so containers stay megabyte-sized and start near-instantly. Trade-off: containers are less strongly isolated than VMs, which is why clouds layer them — provisioned machines are typically VMs, and each VM runs a container runtime hosting many containers, raising utilization and cutting cost. Interview framing: VMs isolate at the hardware level, containers at the process level. Each container should do one thing well (frontend, API, database each in its own container) rather than stuffing a whole stack into one container like a mini-VM.
Official docs:Docker docs: What is a container?
Example
VM: hypervisor → guest OS (4 GB) → app → ~minutes to boot
Container: host kernel → isolated process + image layers → ~milliseconds
# Cloud reality: one VM host, many containers
# VM (AWS EC2) → dockerd → frontend + api + db containersInterview tip
Draw the kernel line explicitly — 'VMs duplicate the kernel, containers share it' — then volunteer the combined pattern (containers on VMs). That shows production awareness.
Common mistakes
- Saying containers are just lightweight VMs without mentioning the shared kernel.
- Recommending one container for the whole stack instead of one concern per container.