5.3.8 · D1MLOps & Deployment

Foundations — Containerization with Docker

2,090 words10 min readBack to topic

This page assumes you know nothing. Before you can read the parent note Containerization with Docker comfortably, every word it uses has to mean something concrete in your head. So we build each symbol, term, and picture from the ground up, in an order where each one leans only on the ones before it.


0. The word "environment" — the picture everything hangs on

Before any Docker term, you must see what an "environment" is.

Look at the figure below. Your program (the amber box) is tiny. The stack of things underneath it — that grey tower — is the environment. Change any one brick in the tower and the amber box on top may crash.

Figure — Containerization with Docker

Why the topic needs this: the parent note's opening line — "it works on my machine" — is entirely about two machines having different towers. Every later idea (image, container, layer) is a strategy for shipping the whole tower instead of just the amber box.


1. Host, kernel, and process — the machine underneath

To understand sharing later, you need three plain words about a computer.

Picture the host as a building, the kernel as the building's single central power-and-plumbing system, and each process as a tenant plugged into that shared system.

Why the topic needs this: the parent claims containers are light because they "share the host's Linux kernel." That sentence is meaningless until you know a kernel is one shared core and a container is just a process — not a whole new building.


2. Isolation — namespaces and cgroups

The parent uses two exact kernel words. Here they are, from zero.

Why the topic needs this: these two features are literally how a container isolates itself without needing its own operating system. Everything the parent calls "lightweight isolation" is namespaces (see) + cgroups (use).


3. Virtual Machine vs Container — the picture that separates them

Now we can draw the comparison the parent makes.

Figure — Containerization with Docker

Look carefully at the two towers:

  • Left (VM): each application sits on top of its own full guest operating system. Every guest OS is gigabytes and takes seconds to boot. The hardware is virtualized underneath them.
  • Right (Container): each application is just a process isolated by namespaces/cgroups. There is no guest OS — every container reuses the one host kernel at the bottom.

Why the topic needs this: the entire reason Docker won is on the right side of this figure — you skip the grey "Guest OS" blocks. If you don't see what got deleted, "lightweight" is just a word.

Connects to Virtual Environments (venv, conda) — those isolate only Python packages; Docker isolates the whole OS-level tower.


4. Filesystem, read-only vs writable, and layers

Now the trickiest picture in the parent note: layers. Build it slowly.

A file marked read-only can be looked at but not changed. A writable file can be edited. Hold onto that distinction — it decides what survives.

Look at the figure: each instruction adds a transparent sheet. Reading the final filesystem is like looking straight down through all the sheets at once — the top-most version of each file wins.

Figure — Containerization with Docker

Let me name the symbols the parent's cost formula uses, before you meet the formula:

  • — the list of layers, from bottom (1) to top (). The subscript is just an index (a position number).
  • — the cost (build time) of layer number . The letter = cost, the little = "which layer".
  • — the index of the first layer that changed since last build.
  • — the summation symbol. It means "add up for every starting at and ending at ." Why this tool? We need one compact way to say "total the costs of the changed layer and everything stacked above it" — a sum is exactly the tool that adds a running list.

So the parent's rebuild cost reads in plain words: "the build time is the sum of the costs of the first changed layer and every layer above it" — because a changed layer forces everything resting on top of it to rebuild too.


5. The Dockerfile vocabulary — one word at a time

The parent's Dockerfile uses seven keywords. Each is just a plain instruction:


6. The three nouns: Dockerfile → Image → Container

Everything above converges here. This is the sentence the whole topic rotates around.


7. Ephemeral vs persistent — volumes

Last foundation, because the parent warns about it as a mistake.

Why the topic needs this: the parent's mistake "the container will remember my model file" is exactly the ephemeral trap. Data you must keep goes in a volume — tying into Reproducibility in ML and Container Registries.


Prerequisite map

Environment = OS + libs + versions

Works on my machine problem

Host machine

Shared kernel

namespaces = what you SEE

cgroups = what you USE

Container = isolated process

Image = frozen environment

Filesystem read-only vs writable

Layers stacked

Dockerfile recipe

Volumes for persistence

Containerization with Docker

This feeds directly into Kubernetes Orchestration, CI-CD Pipelines, and Model Serving with FastAPI once the foundations click.


Equipment checklist

What is an "environment" in one line?
Everything around your code it depends on — OS, libraries, language version, and package versions.
What is the kernel?
The core OS program that talks to hardware and shares it among all processes.
What do namespaces control?
What a process can SEE (files, processes, network) — its private view.
What do cgroups control?
What a process can USE (CPU, memory, disk) — its resource limits.
How does a container differ from a VM?
A container shares the host kernel (no guest OS, MBs, ms boot); a VM ships a whole guest OS (GBs, slow boot).
What is a layer?
One frozen slice of filesystem changes from a single build instruction, stacked read-only.
What does mean here?
Total build cost = sum of the first changed layer's cost plus every layer stacked above it.
Dockerfile, image, container — which is which?
Dockerfile = recipe; image = frozen template; container = running instance.
Does EXPOSE open a port?
No — it is documentation only; -p at run time publishes the port.
Why is the writable layer dangerous for model files?
It is ephemeral (deleted with the container); use a volume for data that must survive.