Docker: the platform and container architecture

  1. Quick summary
  2. Step 1 — Why containers exist: the evolution chain and the "one machine = one purpose" problem
  3. Step 2 — A container is an isolated process that shares the host kernel
  4. Step 3 — An image is read-only layers and layer sharing
  5. Step 4 — Docker architecture and the pull vs build flow
  6. Step 5 — The core mechanisms: namespaces and cgroups (not new at all)
  7. Common misconceptions
  8. Hands-on 1 — Observe the Docker architecture after installation
  9. Hands-on 2 — Prove layer sharing across multiple images
  10. Review questions
  11. Flashcards

Estimated time: 35 minutes.

Quick summary

Step 1 — Why containers exist: the evolution chain and the "one machine = one purpose" problem

A traditional physical machine runs only one environment well at a time (install Java and it is hard to install PHP alongside), and it uses hardware poorly.

Virtualization and cloud raise density; containers push density and deployment speed to the highest level.

The core problem: run many environments (prod/test/dev) at the same time on the same infrastructure, and move applications flexibly between environments without setting up again.

When it breaks: Not grasping this problem leads to overusing physical machines and VMs for everything, which wastes resources and makes deployment slow.

for i in 1 2 3 4 5; do docker run -d --name density-$i nginx:alpine; done
docker stats --no-stream        # MEM USAGE column: each container costs only a few MB, not a whole OS
docker rm -f density-1 density-2 density-3 density-4 density-5

Observe with:

docker stats --no-stream (RAM per container; exact numbers vary by machine) ; compare with the minimum RAM of a VM running a full OS

Step 2 — A container is an isolated process that shares the host kernel

A container runs as a process on the host, isolated by namespaces and limited by cgroups,

sharing the host kernel (Docker:what is a container,

man namespaces(7)).

Inside the container you see its own PID 1 (PID namespace); on the host that same process has a different PID and shows up in the host's process table. This is the core difference from a VM.

When it breaks: Assuming a container has its own kernel/OS leads to misunderstanding security and resource isolation.

docker run -d --name demo busybox sleep 600
docker exec demo ps                              # PID 1 = sleep, only a few processes (PID namespace)
docker inspect --format "{{.State.Pid}}" demo   # the same process, a different PID on the host
docker rm -f demo

Observe with:

docker exec demo ps (inside the container) vs docker inspect --format "{{.State.Pid}}" demo (PID on the host)

Step 3 — An image is read-only layers and layer sharing

An image is built from a chain of read-only layers, one per repackaging;

a container adds a copy-on-write writable layer on top (Docker:storage drivers). docker history shows each layer;

many images with the same base share identical layers, so the total size is smaller than adding them up.

A container holds only what it needs to run (for example, a web app does not need an SSH server), so it is very compact.

When it breaks: Writing important data into the writable layer loses the data when the container is deleted.

docker pull python:3.11
docker pull python:3.12
docker image ls                                  # the real total < the sum, because layers are shared
docker image history python:3.11
docker image inspect --format "{{.Os}} {{.Architecture}}" python:3.11

Observe with:

docker image ls (compare the real size) ; docker image history <image>

Step 4 — Docker architecture and the pull vs build flow

The Docker Host runs the daemon that manages images and containers; the Registry stores images; the CLI gives commands (Docker: overview).

Reading the diagram: a solid line = pull (fetching an existing image), a dashed line = build (from a Dockerfile). In practice most of the time it is a pull; you only build when you need customization.

After installation, docker info shows the default network Docker creates and the root directory that stores images and layers (by default /var/lib/docker) (docker info).

When it breaks: Not distinguishing pull from build leads to confusion about when you need a Dockerfile; ignoring a bloated /var/lib/docker causes production to run out of disk.

docker info | grep -E "Root Dir|Containers|Network"
docker pull nginx        # solid line: pull an existing image
# docker build -t app .  # dashed line: build from a Dockerfile (covered in depth in Part 2)

Observe with:

docker info (default network, Docker Root Dir) ; docker version

Step 5 — The core mechanisms: namespaces and cgroups (not new at all)

Namespaces isolate "what the container sees" (PID/NET/MNT/UTS/IPC/USER — man namespaces(7));

cgroups limit "what the container can use" (CPU/memory/I-O — man cgroups(7)).

Both mechanisms have been in the Linux kernel for decades; cgroups came out of the need to divide up CPU on multi-core machines so that hardware is not wasted. Docker just made them easier to use.

When it breaks: Thinking Docker "invented" isolation leads to misunderstanding its nature; it is really an abstraction layer on top of existing kernel mechanisms.

docker run -d --name demo nginx
lsns | head                                      # the namespaces on the host
docker inspect --format "{{.HostConfig.CgroupParent}}" demo
docker rm -f demo

Observe with:

lsns (lists the namespaces on the host) ; docker inspect (cgroup configuration)

Common misconceptions

Right: A container is an isolated process that shares the host's kernel through namespaces and cgroups; there is no guest OS or separate kernel as in a virtual machine.

Docker defines containers as isolated processes, and when you run many containers "they all share the same kernel",

so a full OS is not needed for each container (Docker:what is a container).

The isolation comes from Linux namespaces (PID/NET/MNT/UTS/IPC/USER — man namespaces(7)), which decide "what the container sees",

while cgroups limit CPU/memory/I-O, that is, "how much the container uses" (man cgroups(7)).

With a virtual machine, a hypervisor virtualizes the hardware, and each VM runs a full OS and kernel.

The consequences: a container drops one operating system layer, so it starts very fast (a few seconds, since all it does is run a process), its image is small because it does not package a kernel,

and the container process appears in the host's process table, quite unlike the hard boundary of a VM.

Right: namespaces and cgroups have been in the Linux kernel for decades; Docker only made them easier to use through a CLI and interface.

Process isolation rests on two kernel-level mechanisms:

namespaces isolate resource spaces (man namespaces(7)) and control groups limit resources (man cgroups(7));

both predate Docker by a long way. cgroups came from the practical need to divide CPU among many processes on one multi-core physical machine (so as not to waste expensive hardware),

which is exactly the foundation containers reuse today.

The consequence: understanding that containers are "not new" removes the illusion of magic.

Docker just packages existing Linux mechanisms behind a simple CLI, much as iptables hides the complexity of low-level packet filtering.

Right: Containers are immutable: every run is exactly the image version at the time of creation; for a lasting change you must build a new image and replace the container.

Data that must last has to be written to a volume outside the host.

A container runs from an image made of read-only layers; changes at run time live only in a thin writable layer, and "when a container is destroyed,

the writable layer is destroyed with it" (Docker:volumes, storage drivers).

Hot-editing a file in a running container takes effect immediately but is only a "temporary patch"; delete the container and run it again from the same image, and every change disappears and the content returns to the image's default.

The consequence: the right way is to edit at the source (the Dockerfile or source code) and build a new image; any state that must last (databases, uploads) has to live in a volume or bind mount outside the container's lifecycle.

Right: A container depends only on the kernel underneath, not on a specific distro; thanks to the open OCI standard, images and registries from different vendors are cross-compatible across Docker, Podman, and containerd.

Traditional Linux packages are locked to a distro (Ubuntu uses Ubuntu repositories, not RedHat's RPM repositories).

Containers are different: a container packages the application and the libraries it needs and relies only on the host kernel,

so it "runs consistently on any infrastructure" (Docker:what is a container).

The cross-compatibility comes from the open OCI (Open Container Initiative) standard, which defines the image format and runtime that Docker, Podman, and containerd all follow (Open Container Initiative).

The consequence: an image built once can be pulled and run from Docker Hub, quay.io, Harbor, GitLab Registry, and so on, with different runtimes, so you are not locked into one vendor.

Hands-on 1 — Observe the Docker architecture after installation

10 minutes

Before running your first container, read docker info to see the Docker environment: the bridge network Docker creates by itself, the root directory that stores images and layers,

and the number of containers (docker info).

Build the habit of "check the information before you act".

docker version && docker info

1. Check the client and server: docker version.

It shows the Client and Server (Engine) versions, confirming that the daemon is running.

2. Get an overview of the environment: docker info. Pay attention to the Docker Root Dir line and the Network section.

Docker Root Dir is usually /var/lib/docker; there is a default network (bridge) that Docker creates at install time.

3. Compare: before installing Docker the machine has only localhost plus its physical interface; after installation it also has its own bridge.

This shows that Docker adds a bridge network layer for containers.

Analysis

Observation: docker info shows the Docker Root Dir and the bridge network created by Docker.

Mechanism: The daemon creates the bridge network and the directory that stores layers and images when it initializes the Docker environment.

Takeaway: The /var/lib/docker directory grows over time, so it should be placed on a large partition or disk from the start.

Troubleshooting:

Hands-on 2 — Prove layer sharing across multiple images

10 minutes

Pulling two (or three) python versions and comparing the real total size against the sum of the individual sizes shows that the images share identical base layers (Docker: storage drivers).

docker pull python:3.11 && docker pull python:3.12 && docker image ls

1. Pull two versions: docker pull python:3.11 then docker pull python:3.12.

The second pull downloads faster because many base layers are already present (it shows "Already exists").

2. List the images: docker image ls and add up the size of each line in your head.

The real total size on disk is smaller than the sum of the individual images.

3. Look at the shared layers: docker image history python:3.11 and docker image history python:3.12.

Many of the first layers (the base) are identical between the two images.

Analysis

Observation: Pulling the second image shows "Already exists" for the base layers; the real total size < the sum.

Mechanism: Docker stores one copy of each layer and shares it among images with the same base (layer contents are identified by digest).

Takeaway: Layer sharing saves space and bandwidth when you run many images from the same family.

Review questions

Question 1. In the infrastructure evolution chain, what step comes immediately BEFORE "cloud"?

  1. Physical

  2. Virtualization

  3. Container

  1. Serverless

Answer: Virtualization. The evolution chain: physical → virtualization → cloud → container.

Virtualization (VMware/KVM/Hyper-V) is the foundation of the cloud (OpenStack/CloudStack) before containers came along.

Question 2. What is the core difference between a container and a virtual machine?

  1. Containers run faster thanks to a more powerful CPU

  2. Containers share the host kernel and have no guest OS of their own like a VM

  3. Containers do not need hardware

  1. A VM cannot run Linux

Answer: Containers share the host kernel and have no guest OS of their own like a VM.

A container is an isolated process that "shares the same kernel" with the host,

dropping the guest OS layer that every VM must have through a hypervisor (Docker:what is a container),

which is why it is light and starts fast.

Question 3. Which Linux mechanism isolates "what the container sees" (processes, network, mounts)?

  1. cgroups

  2. namespaces

  3. hypervisor

  1. systemd

Answer: namespaces.

Namespaces isolate the resources a container sees (PID/NET/MNT/UTS/IPC/USER —

man namespaces(7)). cgroups limit the AMOUNT of resources that can be used (man cgroups(7));

they do not isolate visibility.

Question 4. Why is the total size smaller than the sum of the individual sizes when you pull several python images (3.11, 3.12, 3.13)?

  1. Docker compresses the images

  2. The images share identical base layers

  3. Docker keeps only the newest image

  1. The python image is inherently very small

Answer: The images share identical base layers.

An image consists of read-only layers; images from the same family inherit identical base layers, and Docker stores only one copy of each layer, shared among the images (Docker: storage drivers).

Question 5. Which standard makes images and registries cross-compatible across Docker, Podman, and containerd?

  1. POSIX

  2. OCI (Open Container Initiative)

  3. HTTP

  1. ISO 9001

Answer: OCI (Open Container Initiative).

OCI defines the common image format and container runtime that Docker, Podman, and containerd all follow (Open Container Initiative), so an image is not locked into one vendor.

Question 6. What is the right way to make a LASTING change to the application contents in a container?

  1. exec into the container, edit the file, and leave it as is

  2. Edit at the source (Dockerfile or source code) → build a new image → replace the container

  3. Use docker pause to keep the change

  1. Write directly into /var/lib/docker on the host

Answer: Edit at the source (Dockerfile or source code) → build a new image → replace the container. Containers are immutable: a hot edit is only temporary and is lost on recreate.

The right way is to edit the source, then build a new image and replace; state that must last is written to a volume (Docker: volumes).

Flashcards

A container shares the host kernel (a process isolated by namespaces and cgroups); a VM runs its own OS and kernel through a hypervisor. Explains why containers are light and start fast.

namespaces isolate "what is seen" (PID/NET/MNT/UTS/IPC/USER); cgroups limit "how much is used" (CPU/memory/I-O).

No. namespaces and cgroups have been in the Linux kernel for decades; Docker only made them easier to use.

An image = a chain of read-only layers; many images with the same base share layers, and Docker stores one copy of each layer.

Every run is exactly the image version; to change it you must build a new image and replace, not edit in place for the long term.

No. Docker is only a runtime environment; data that must last has to be written to a volume outside the host, otherwise it is lost when the container is deleted.

Docker Host/daemon (dockerd) manages images and containers · Registry stores images · CLI (build/pull/run) gives commands.

The Open Container Initiative: an open standard defining the image format and runtime, making Docker, Podman, containerd, and registries cross-compatible.

Docker: the platform and container architecture