python:3.12-slimrequirements.txtpip installapp.py · 1.0app.py · 1.1ghcr.io · REGISTRYbasereqdeps1.01.1shop:1.0shop:1.11FROM python:3.12-slim2WORKDIR /app3COPY requirements.txt .4RUN pip install -r requirements.txt5COPY app.py .6CMD ["python", "app.py"]DOCKERFILENODE · KUBELETbasereqdepsapp.py 1.1
Stack: the image's layers, bottom to topFront: the Dockerfile, and a Kubernetes nodeParcels: layers moving to and from the registryA container image is a stack of read-only layers built from a Dockerfile, one layer per file-changing line. Rebuilding after a code change reuses the cached layers below it; pushing and pulling move only the layers the other side lacks, because a registry stores every layer under its sha256 digest. On a Kubernetes node the kubelet pulls the image and the container runs as those layers plus one writable layer. The base image is itself several layers; the figure draws them as one slab. Lines that change files (RUN, COPY, ADD) add layers; CMD and WORKDIR are stored as settings in the image config, though WORKDIR may also add a small layer when it has to create the folder.

The idea

  1. A container image is a read-only package: your app plus every file it needs, from Linux system files to Python and its libraries. A running copy of an image is a container. Images are built as a stack of layers.

Build: a Dockerfile, layer by layer

Share: tags, registries, the cache

Run: pull and start

What happens

;; step 1/11 · image
image      = app + everything it needs, read-only
container  = an image, running

our image, top to bottom:
  app.py                (our code)
  pip install           (libraries)
  requirements.txt      (a list of libraries)
  python:3.12-slim      (Linux + Python)

The base image is itself several layers; the figure draws them as one slab. Lines that change files (RUN, COPY, ADD) add layers; CMD and WORKDIR are stored as settings in the image config, though WORKDIR may also add a small layer when it has to create the folder. ghcr.io/acme/shop is an example name. The Dockerfile, requirements.txt and app.py are real files; the lesson tests compile app.py with python3.