What is Docker and how do containers differ from Virtual Machines?
Quick Summary: Docker packages applications and runtime dependencies into portable images running as lightweight isolated processes sharing the host Linux kernel (via namespaces and cgroups), unlike Virtual Machines which boot complete separate guest OS kernels via a hypervisor.
Direct Interview Answer
A Virtual Machine virtualizes hardware and boots an entire guest operating system per VM, taking minutes to boot and gigabytes of overhead.
A Docker Container uses Linux namespaces (isolating PIDs, network interfaces, mounts, users) and cgroups (capping CPU/RAM) to isolate applications on the shared host kernel—starting in milliseconds.
Detailed Technical Explanation
Understanding this distinction clarifies two practical facts: containers are faster and denser than VMs, yet share the host kernel boundary—so hardening images (non-root user, read-only filesystem, minimal base packages) remains critical.
Practical Walkthrough
Inspecting running image layers and verifying non-root process ownership inside a container.
docker run --rm --read-only --user 10001:10001 alpine:3.20 id
uid=10001 gid=10001
Real-World Production Use Case
Packaging identical microservices across developer laptops, GitHub Actions CI, and production EKS clusters with zero "works on my machine" drift.
Common Interview Mistakes to Avoid
- Assuming Docker containers run their own separate Linux kernel on Linux hosts.
- Running production app processes as default root (UID 0) inside containers.