Interview's MateDocker
Interview's Mate

Docker

Compose · Networking · Security · Ops

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Docker topics
Lesson 1/ 160
01. Containerization & Docker Fundamentals

What are Containers? (Containers vs Virtual Machines)

Understand process isolation, shared kernels, and when containers beat VMs for packaging apps.

BeginnerIsolation · Shared Kernel3 quiz questions
Practice DevOps Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

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-alpine for 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

Loading interactive 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.

Concrete Isolation setup

docker run --rm --name web -p 127.0.0.1:8080:80 nginx:1.27-alpine

Key takeaway: Prove Shared Kernel with 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.

Deliberate failure test

Exercise this failure safely: expecting a Linux container to run a Windows kernel or a different Linux kernel ABI without a matching VM/host.

Key takeaway: Containers deliver much higher density and faster startup than VMs, while accepting a smaller kernel-isolation boundary.

How it works, step by step

Step 1 of 4
Design

1. 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.

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.
Key numbers at this step
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 membership in 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

Explicit Isolation
Best for: Understand process isolation, shared kernels, and when containers beat VMs for packaging apps, with a reviewed runbook.

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.

Ambient default
Best for: Short-lived Shared Kernel experiments with low blast radius.

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.

Managed Density
Best for: Teams that centralize Density policy across many workloads.

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-alpine as proof and skipping docker 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-alpine address 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?
Interview tip: Give one concrete operation-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

Loading quiz

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.

Open DevOps Q&A →Tech Learn Q&A
Next topic
History & Evolution of Linux Containers (LXC, Docker, OCI)