4.5.11 · D1Software Engineering

Foundations — Docker — images, containers, Dockerfile, docker-compose

1,893 words9 min readBack to topic

Before you can read a single Docker command in the parent note, you need a handful of words that the parent assumes you already own: what a "process" is, what a "filesystem" is, what a "kernel" is, what a "port" is. This page builds every one of them from absolute zero, in the order they depend on each other.


0. The most basic picture: what is a computer running your app?

Everything below sits on top of one image. Look at it before anything else.

Figure — Docker — images, containers, Dockerfile, docker-compose

1. Filesystem — the tree of files a program can see

Figure — Docker — images, containers, Dockerfile, docker-compose

Look at the tree in the figure. Two ideas hide inside it:

  1. A path is an address. /app/app.py is a route: start at the root /, go into app, pick the file app.py. This is why the parent's Dockerfile says WORKDIR /app — it sets the starting folder so later paths can be short.
  2. Two programs can be handed two different trees. This is the whole magic. If I give your web app a filesystem where /usr/bin/python is Python 3.12, and give another app a tree where it is Python 3.8, they never collide — even on one machine.

2. Isolation — the bubble, made of namespaces and cgroups

The parent drops two Linux terms without unpacking them: namespaces and cgroups. They are the two walls of the bubble.

Figure — Docker — images, containers, Dockerfile, docker-compose

3. Port and port mapping — the numbered doors

Figure — Docker — images, containers, Dockerfile, docker-compose

Because a container lives in its own network bubble, its port 8000 is inside the bubble — the outside world can't knock on it directly. So Docker installs a forwarding rule:


4. Environment variable — a labelled note pinned to the process


5. Ephemeral vs persistent — why data vanishes


6. YAML and DNS hostname — the compose vocabulary


How these foundations feed the topic

process

container

kernel

namespaces

isolation

cgroups

filesystem

diff

layer

image

port

port mapping

docker run

environment variable

docker-compose

YAML

DNS hostname

volume

persistent data

Read it top-down: process + kernel + isolation give you a container; filesystemdifflayer give you an image; ports, env vars, YAML and hostnames are the extra words you need before docker-compose makes sense.


Equipment checklist

Cover the right side and test yourself. If any answer is fuzzy, re-read its section before opening the parent.

A process is
one running program plus the memory it is currently using.
The kernel is
the core of the OS that talks to hardware and hands resources to every process; all containers share the host's one kernel.
A filesystem is
the tree of folders and files a program can see, addressed by paths like /app/app.py.
A diff is
the list of changes (added / changed / deleted files) between a before-tree and an after-tree — the basis of a layer.
A namespace
makes a process see only its own bubble (its own processes, its own files) — the walls of isolation.
A cgroup
caps how much CPU/memory a process may use — the rations of isolation.
A port is
a numbered door for network traffic that says which program the traffic is for.
-p 8080:8000 means
host door 8080 forwards to container door 8000 — left is outside (host), right is inside (container).
An environment variable is
a named text value handed to a process at start, so config isn't hard-coded.
Ephemeral means
gone when its holder disappears — like a container's writable layer.
A volume is
storage kept outside the container so data survives deletion.
YAML is
an indentation-based plain-text format for describing structured data, used by docker-compose.yml.
A DNS hostname is
a friendly name standing in for a network address, letting web reach db by name.