Containers versus virtual machines
Quick answer
A Linux container runs ordinary processes with restricted views of system resources. A virtual machine runs a guest kernel on virtual hardware. Choose the boundary according to workload, trust and operating-system requirements, not just startup speed.
Imagine two workloads requiring different kernel versions: separate guests can supply those versions, whereas ordinary Linux containers share their host kernel. Container isolation is not equivalent to a separate guest kernel; choose the boundary using trust and compatibility requirements.
Prepare the practice environment
Run python3 lab-fixtures/containers-virtualization/setup.py from the extracted root as an ordinary user. Enter the printed private path and check pwd. Use fresh fixtures, Bash with set -e -o pipefail, LC_ALL=C and umask 077. The Python helper parses fictional examples or inspects its own child. No runtime daemon, external network or root access is needed. Do not apply the fictional JSON to any runtime. Version checks need the named tools.
Prerequisites
Review: Kernel configuration and release lifecycle, Threads, clocks and credentials, Packet capture and VPN concepts.
How it works
Containers normally share the kernel of their Linux host (which may itself be a VM). Images supply userspace files; namespaces change resource visibility, cgroups account for and constrain resources, and access controls restrict operations. A VM has its own guest kernel; a hypervisor mediates CPU and memory, and virtual devices provide storage and networking. Hardware virtualization can accelerate execution, while full emulation can support a different CPU architecture at a cost. Neither boundary guarantees security. A kernel vulnerability can affect containers sharing that kernel; hypervisor and device-model vulnerabilities can affect VMs. Use separate VMs or hosts for stronger trust separation where required. A container image is not a bootable VM disk by default. On non-Linux desktops Linux containers commonly run inside a Linux VM. Inspection tools give hints, not proof of isolation strength.
Try the examples
This reports the kernel interface in the current environment, not whether the host is physical.
Expected stdout:
Linuxif systemd-detect-virt --quiet; then printf 'virtualization detected\n'else printf 'none detected or detection unavailable\n'fiThe local result is shown; other systems may produce the second line. Detection is heuristic and may report the innermost virtualization.
Expected stdout:
virtualization detectedThe fixed model labels two architectures, not actual runtime security.
Expected stdout:
container: shared kernelvm: guest kernelCommon mistakes
Do not infer isolation from a hostname or image name. A Linux image with a different distribution version still uses the host kernel. Do not treat a VM snapshot as a backup.
Practice
Draw the boundary for two trusted web services and a workload requiring a different guest kernel. Explain which resources are shared and what needs independent backup.
Related references
Study: systemd-detect-virt. These are reference names, not deployed links.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Containers versus virtual machines — Knowledge Check
Apply container and virtualization concepts to concrete local examples.
What normally runs inside a Linux container?
Which workload requires a separate guest kernel?
What does an image primarily supply?
Does detecting virtualization prove strong isolation?