Galle, LK--:--5/6 sites live

Containers vs Virtual Machines & Docker Architecture

"It works on my machine" was the bane of software engineering. Docker solved this forever by packaging an application together with its runtime, dependencies, system libraries, and configurations into a…

4 Jun 20263 min readSelf Guide · Stage 3#Docker#Containers#W3DevOps

Lesson 4 of 26 · Module: Docker

15 min read · Source notes — Videos: Docker Full Course & Docker Mastery

"It works on my machine" was the bane of software engineering. Docker solved this forever by packaging an application together with its runtime, dependencies, system libraries, and configurations into a portable, reproducible image.

Screenshot: Docker Fundamentals & Motivation

Instructor explaining container isolation compared to legacy hypervisor architectures.

Containers vs Virtual Machines: The Technical Difference

FeatureVirtual Machine (VM)Container (Docker)
KernelContains its own full Guest OS kernelShares the Host OS Linux kernel
Isolation LevelHardware-level (via Hypervisor Type 1/2)Process-level (via Linux kernel namespaces)
Startup TimeMinutes (boots full OS, systemd, drivers)Milliseconds (instantiates a sandboxed process)
Storage FootprintGigabytes (10GB - 40GB per VM)Megabytes (5MB Alpine to ~150MB Debian slim)
Resource UsagePre-allocated RAM & CPU slicesDynamic: consumes only what process uses

Screenshot: Container Technology Overview

Detailed visual comparison of host hypervisors vs container runtime daemons.

How the Linux Kernel Creates Containers

Docker is not a virtual machine. A container is simply an ordinary Linux process running with kernel constraints:

  • Namespaces (Isolation): pid: Process IDs (container PID 1 appears as a regular PID on host) net: Dedicated network interfaces, IP addresses, and routing tables mnt: Isolated filesystem mounts and root directory pivot ipc: Inter-process communication memory queues uts: Hostname and domain name isolation user: User ID and Group ID mappings
  • cgroups (Control Groups - Resource Limits): Enforces hardware constraints such as --memory="512m" and --cpus="1.5". If a container exceeds its memory limit, the Linux kernel invokes the OOM (Out Of Memory) killer.

Docker Engine Architecture

Output
1. Docker CLI Client: Terminal utility (`docker build`, `docker run`)
   ↓
REST API (Unix Socket: /var/run/docker.sock)
   ↓
2. Docker Daemon (dockerd): Manages images, containers, networks, volumes
   ↓
gRPC
   ↓
3. containerd & runc: OCI-compliant runtime that interfaces with Linux kernel primitives

Keep going: ← Lesson 3 · Lesson 5 → · Module overview · Track it in the Self Guide