What is Docker and how does containerization differ from virtual machines?
Learn what Docker is and how containers differ from virtual machines — shared kernel, namespaces, cgroups, and why containers start in milliseconds.
Expected Interview Answer
Docker is a platform for building, packaging, and running applications inside containers — lightweight, isolated processes that share the host operating system's kernel while bundling their own code, runtime, and dependencies.
Containers differ from virtual machines in what they virtualize. A VM runs a full guest operating system on top of a hypervisor, so each VM carries its own kernel, boots slowly, and consumes gigabytes. A container virtualizes at the OS level using Linux kernel features like namespaces (isolation) and cgroups (resource limits), sharing the host kernel. That makes containers start in milliseconds, use megabytes instead of gigabytes, and pack far more densely onto the same hardware.
- Starts in milliseconds versus minutes for a VM
- Far smaller footprint — no duplicated guest OS
- Consistent 'build once, run anywhere' environments
- Higher density: many more containers per host
- Fast, reproducible deployments and rollbacks
AI Mentor Explanation
A virtual machine is like giving every batter their own entire stadium — pitch, stands, and floodlights — just to face a few balls, which is wasteful. A container is like sharing one stadium's ground and lights while each batter brings only their own bat, pads, and gloves. Docker is the stadium management that hands each player a ready kit and lets many bat in nets simultaneously on shared turf.
Step-by-Step Explanation
Step 1
Package the app
Write a Dockerfile describing the base image, dependencies, and startup command for your application.
Step 2
Build an image
Run docker build to produce an immutable, layered image containing everything the app needs to run.
Step 3
Share the kernel
Docker uses Linux namespaces and cgroups to isolate the container while it reuses the host kernel — no guest OS.
Step 4
Run containers
docker run starts one or more isolated container instances from the image in milliseconds.
Step 5
Compare to a VM
Note that a hypervisor-based VM would instead boot a full guest OS per instance, costing more time and memory.
What Interviewer Expects
- Clear definition of Docker as a container platform
- Understanding that containers share the host kernel
- Knowledge of namespaces and cgroups
- Contrast of hypervisor vs OS-level virtualization
- Awareness of startup speed and footprint trade-offs
Common Mistakes
- Claiming a container includes its own full operating system
- Saying containers are just lightweight virtual machines with no real difference
- Confusing the Docker image with the running container
- Ignoring the shared-kernel security implications
- Believing containers always provide stronger isolation than VMs
Best Answer (HR Friendly)
“Docker packages an application together with everything it needs into a container that runs the same way on any machine. Unlike a virtual machine, which carries a whole separate operating system, a container shares the host's operating system, so it is much smaller and starts almost instantly.”
Code Example
# Pull an image and run it as an isolated container
docker run -d --name web -p 8080:80 nginx:alpine
# List running containers
docker ps
# See how little the container weighs vs a VM's gigabytes
docker image ls nginx:alpineFollow-up Questions
- What are Linux namespaces and cgroups, and how does Docker use them?
- When would you still choose a virtual machine over a container?
- How does the shared kernel affect container security isolation?
- What is the Docker daemon and how does the client talk to it?
MCQ Practice
1. What does a container primarily share with its host that a virtual machine does not?
Containers share the host OS kernel via namespaces and cgroups, whereas each VM runs its own guest kernel on a hypervisor.
2. Which Linux kernel feature does Docker use to limit a container's CPU and memory?
Control groups (cgroups) enforce resource limits, while namespaces provide isolation of processes, network, and filesystem views.
3. Why do containers typically start much faster than virtual machines?
Containers reuse the already-running host kernel, so there is no guest OS boot sequence, letting them start in milliseconds.
Flash Cards
What is Docker? — A platform to build, package, and run applications inside lightweight, isolated containers that share the host OS kernel.
Container vs VM in one line? — A container virtualizes the OS and shares the host kernel; a VM virtualizes hardware and runs a full guest OS on a hypervisor.
Which kernel features power containers? — Namespaces for isolation and cgroups for resource limits.
Why are containers smaller than VMs? — They do not bundle a guest operating system — only the app, runtime, and dependencies.