Docker deep dive

Layers, multi-stage builds, image size, non-root users, healthchecks. The difference between a 2GB and 80MB image is interview gold.

About 20 min read3-question knowledge check

The mental model

A container is not a small virtual machine. A VM is a whole house with its own foundations, plumbing, and boiler — a full guest kernel on virtual hardware. A container is a locked room in a shared building: it uses the building's plumbing (the host kernel) but the walls are drawn so that the occupant sees only its own furniture. Those walls are two ordinary Linux kernel features — namespaces decide what a process can *see* (its own PIDs, network interfaces, mounts, hostname), and cgroups decide how much it can use (CPU, memory, I/O).

An image is the flat-pack furniture kit; a container is one assembled room built from it. Images are built in layers, and each layer is a read-only diff stacked on the one below, addressed by a content hash. The build cache works exactly like a photocopier that stops copying the moment one page differs: layers are reused until the first instruction whose inputs changed, and everything after that is rebuilt. That single fact explains almost every Dockerfile best practice — order your instructions from least to most frequently changing.

Why this matters for DevOps: the gap between a 2 GB image that takes four minutes to pull and an 80 MB image that pulls in six seconds is entirely layer discipline and multi-stage builds. Multiply by every node, every deploy, every autoscale event, and it becomes a real reliability and cost number.

The full lesson continues with 15 more sections
  • Deep dive
  • Internal architecture
  • Real-world use cases
  • Best practices
  • Common mistakes
  • Performance
  • Security
  • Production troubleshooting
  • Advantages & disadvantages
  • Alternatives
  • Interview expectations
  • Interview questions
  • Facts to remember
  • Cheat sheet
  • Quick revision