Skip to main content
Foundations: web, servers, containersLesson 10 of 13

How an Image Is Built and Run

Follow what an image, the source of a container, is made of, what name it carries, and where it is stored before it becomes a container. Running the build automatically in a pipeline is covered in How a Pipeline Runs, and how a node's kubelet and runtime pull the image and start a Pod is covered in How a Pod Starts. Here we focus on the image itself.

Imageweb:1.4.2
Image locationBuild machine
Vuln scan—
Running containers—
DockerfileBuild recipeImageRead-only source4 layersHarborRegistryVuln scanTrivyNodePulls the imageContainer 1webContainer 2webVolumeOutside storageBuild
RequestResponse / reportAppears in a later step

What you will learn

  • Each Dockerfile line becomes one layer
  • How to read an image name: registry, project, name, tag
  • Why the latest tag is risky, and what a digest is
  • "Not scanned" is not the same as "0 vulnerabilities"
  • Deleting a container deletes the data written inside it

Easily confused pairs​

PairDifference
Image / containerAn image is the read-only source. A container is that image running (a process)
RUN / CMDRUN runs once at build time. CMD runs every time a container starts
Tag / digestA tag is a label that can move. A digest is a fixed unique value computed from the content
latest / 1.4.3latest does not automatically point to the newest. Production uses tags that pin a version
Not scanned / 0 vulnerabilitiesNo result because there is no scanner is not the same as scanned and found none
EXPOSE / actual exposureEXPOSE only documents a port. It does not make the port reachable from outside

Try it yourself​

docker image history <image> # Layers and the line that made each
docker image inspect <image> --format '{{.RepoDigests}}' # Digest: the content fingerprint
docker pull <image> # Layers already present are skipped
trivy image <image> # Vulnerabilities by severity (if Trivy is installed)
kubectl get pod <pod> -o jsonpath='{.status.containerStatuses[*].imageID}' # Digest the node actually pulled

Check yourself

  1. Two servers both run web:latest but behave differently. What is the most likely reason?
  2. An app writes uploaded files inside its container. The container is deleted and recreated. What happens to the files?
  3. Harbor shows no vulnerability results for an image. What can you conclude?

Further reading: Images (Kubernetes docs) · Docker Build · Harbor · How a Pod Starts