What are Containers? (Containers vs Virtual Machines)
Understand process isolation, shared kernels, and when containers beat VMs for packaging apps.
In plain words
It is a light, packaged copy of an app environment that runs as an isolated process on the host rather than as a complete computer.
Think of it like…
A fleet of shipping containers is stacked on one ship: every box has its own contents, but every box relies on the same hull and captain-the host kernel and daemon.
Where you’ve seen it
In practice, docker run --rm --name web -p 127.0.0.1:8080:80 nginx:1.27-alpine is the concrete move for this job: understand process isolation, shared kernels, and when containers beat VMs for packaging apps. The release is not accepted until docker inspect --format {{.State.Pid}} web, then compare /proc/$PID/ns and cgroup membership confirms the result.
Words you’ll hear
- Isolation
- The implementation control in
docker run --rm --name web -p 127.0.0.1:8080:80 nginx:1.27-alpinefor understand process isolation, shared kernels, and when containers beat VMs for packaging apps. - Shared Kernel
- The result to observe with
docker inspect --format {{.State.Pid}} web, then compare /proc/$PID/ns and cgroup membership, rather than infer from a successful command alone. - Density
- The production boundary exposed when expecting a Linux container to run a Windows kernel or a different Linux kernel ABI without a matching VM/host.
Visual diagram
Theory & deep dive
Isolation control path
The concrete mechanism is docker run --rm --name web -p 127.0.0.1:8080:80 nginx:1.27-alpine. The observable result is docker inspect --format {{.State.Pid}} web, then compare /proc/$PID/ns and cgroup membership; if those disagree, inspect the runtime evidence before changing unrelated settings.
Understand process isolation, shared kernels, and when containers beat VMs for packaging apps. Keep Isolation, Shared Kernel and Density in the same deployment record so the intent and the observed state cannot drift apart.
docker run --rm --name web -p 127.0.0.1:8080:80 nginx:1.27-alpine
docker inspect --format {{.State.Pid}} web, then compare /proc/$PID/ns and cgroup membership, not with command success alone.Density failure boundary
Containers reduce image-to-host drift and start quickly, but they are not a security boundary equivalent to a separate VM. Strong multi-tenant isolation may need hardened runtimes or microVMs because a shared-kernel exploit can escape more containers at once. The narrow failure to design for is expecting a Linux container to run a Windows kernel or a different Linux kernel ABI without a matching VM/host.
Accept this compromise explicitly: Containers deliver much higher density and faster startup than VMs, while accepting a smaller kernel-isolation boundary. The controlled check-docker inspect --format {{.State.Pid}} web, then compare /proc/$PID/ns and cgroup membership-also identifies the point where a different design is safer.
Exercise this failure safely: expecting a Linux container to run a Windows kernel or a different Linux kernel ABI without a matching VM/host.
How it works, step by step
Step 1 of 41. State the boundary
Write down why the workload needs this: Containers reduce image-to-host drift and start quickly, but they are not a security boundary equivalent to a separate VM. Strong multi-tenant isolation may need hardened runtimes or microVMs because a shared-kernel exploit can escape more containers at once.
- Intent
- Isolation
When to use it & trade-offs
What it is
A container is an isolated process tree plus a packaged filesystem, but it shares the host kernel; a VM adds a guest kernel and virtual hardware. Namespaces change what the process can see, cgroups constrain what it can consume, and image layers supply its filesystem.
Why it matters: Containers reduce image-to-host drift and start quickly, but they are not a security boundary equivalent to a separate VM. Strong multi-tenant isolation may need hardened runtimes or microVMs because a shared-kernel exploit can escape more containers at once.
When to reach for it
- The fit is strongest for this job: understand process isolation, shared kernels, and when containers beat VMs for packaging apps. Pair it with
docker inspect --format {{.State.Pid}} web, then compare /proc/$PID/ns and cgroup membershipin the runbook. - Production Isolation changes should make Shared Kernel observable through
docker run --rm --name web -p 127.0.0.1:8080:80 nginx:1.27-alpine, rather than trusting the runtime default. - Keep a rollback example for the case where expecting a Linux container to run a Windows kernel or a different Linux kernel ABI without a matching VM/host.
When to avoid or be careful
- Do not accept command success while the system can still fail by expecting a Linux container to run a Windows kernel or a different Linux kernel ABI without a matching VM/host.
- Avoid erasing Density protection merely to dodge this cost: “Containers deliver much higher density and faster startup than VMs, while accepting a smaller kernel-isolation boundary”.
- Do not replace the evidence path-
docker inspect --format {{.State.Pid}} web, then compare /proc/$PID/ns and cgroup membership-with a screenshot or a mutable tag.
docker run --rm --name web -p 127.0.0.1:8080:80 nginx:1.27-alpine: practical choices
Strengths: A container is an isolated process tree plus a packaged filesystem, but it shares the host kernel; a VM adds a guest kernel and virtual hardware. Namespaces change what the process can see, cgroups constrain what it can consume, and image layers supply its filesystem.
Watch out: Containers deliver much higher density and faster startup than VMs, while accepting a smaller kernel-isolation boundary.
Strengths: It can begin with docker run --rm --name web -p 127.0.0.1:8080:80 nginx:1.27-alpine and fewer surrounding controls.
Watch out: It silently accepts expecting a Linux container to run a Windows kernel or a different Linux kernel ABI without a matching VM/host, which makes the result hard to reproduce after promotion.
Strengths: Containers reduce image-to-host drift and start quickly, but they are not a security boundary equivalent to a separate VM. Strong multi-tenant isolation may need hardened runtimes or microVMs because a shared-kernel exploit can escape more containers at once.
Watch out: The platform adds an ownership and debugging layer; retain docker inspect --format {{.State.Pid}} web, then compare /proc/$PID/ns and cgroup membership as the direct check.
Interview signals & numbers to know
When this topic comes up
- docker run --rm --name web -p 127.0.0.1:8080:80 nginx:1.27-alpine
- docker inspect --format {{.State.Pid}} web, then compare /proc/$PID/ns and cgroup membership
- Failure signature: expecting a Linux container to run a Windows kernel or a different Linux kernel ABI without a matching VM/host
- Trade-off: Containers deliver much higher density and faster startup than VMs, while accepting a smaller kernel-isolation boundary.
Benchmarks & rules of thumb
- 1 host kernel
- shared by all Linux containers
- 2 core controls
- namespaces for visibility, cgroups for resources
- seconds
- typical container start versus minutes for many VM boots
Common mistakes & follow-ups
Common interview mistakes
- Treating a successful
docker run --rm --name web -p 127.0.0.1:8080:80 nginx:1.27-alpineas proof and skippingdocker inspect --format {{.State.Pid}} web, then compare /proc/$PID/ns and cgroup membership. - Expecting a Linux container to run a Windows kernel or a different Linux kernel ABI without a matching VM/host
- Optimizing Isolation without accepting that containers deliver much higher density and faster startup than VMs, while accepting a smaller kernel-isolation boundary.
Likely interviewer follow-ups
- Why does
docker run --rm --name web -p 127.0.0.1:8080:80 nginx:1.27-alpineaddress Isolation here rather than through application code? - How would you distinguish healthy Shared Kernel from the failure “expecting a Linux container to run a Windows kernel or a different Linux kernel ABI without a matching VM/host” using
docker inspect --format {{.State.Pid}} web, then compare /proc/$PID/ns and cgroup membership? - When would this trade-off-“Containers deliver much higher density and faster startup than VMs, while accepting a smaller kernel-isolation boundary”-justify a different Density design?
docker run --rm --name web -p 127.0.0.1:8080:80 nginx:1.27-alpine-and one proof-docker inspect --format {{.State.Pid}} web, then compare /proc/$PID/ns and cgroup membership. Then name the boundary: expecting a Linux container to run a Windows kernel or a different Linux kernel ABI without a matching VM/host.Knowledge check
Put it into practice
Practice related interview Q&A
Apply What are Containers? (Containers vs Virtual Machines) with generative AI interview Q&A and hands-on practice.