TOPIC 05/1916 MINNOT STARTED

Docker part 2: write a Dockerfile and build your own test image

Write a short Dockerfile, build an image from it, run it, and read the build output, so the same test set-up starts on any machine or pipeline.

L1–L4 are part of the Pro pass

L0 Explain simply

Analogy: a recipe card for a lunch box. The card lists the base box, each item to add and the note on the lid. Anyone who follows the card packs the same lunch. The kitchen shelf you may take food from is only the counter in front of you, not the whole house.

The card is the Dockerfile. Each packing step is an . The counter is the .

Tom, a tester at Daily List, a to-do list app, writes the card for his pytest setup. Leo wants the same lunch on every laptop.

What it is: A Dockerfile is a text file of steps that Docker reads when you run docker build. An image layer is one saved step, and Docker can reuse it next time. The build context is the folder of files you allow Docker to copy, usually the . you pass in. docker run is the neighbour, and it starts a container from an image that already exists. Build makes the image, and run does not.

Why it matters: Without a Dockerfile, Daily List tests depend on whatever Python happens to be on Tom's laptop. Mei and Leo get different packages and a different . The file pins the base image and installs from requirements.txt. It sets the start command to pytest, so (CI) and the laptop share one setup.

PLAIN WORDS · 2 in this section
pytest
A free Python tool that finds and runs checks.
reuse
to use something again

PICTURE IT

The picture is the one the lesson above opens with. The table below shows how each part of it matches the software.

THE REAL JOB A recipe card for a lunch box.

  1. Card
  2. Pack
  3. Shelf
Lunch box

HOW THE PICTURE MAPS

How each part of the picture matches the software
In the pictureIn the software
The recipe cardThe Dockerfile
A packing stepAn image layer
The kitchen shelf you may take fromThe build context
The packed lunchThe image

WHERE THIS PICTURE STOPS

  • A card is read once, but a Dockerfile is run on every build.
  • Items are packed in order, but unchanged layers are used again.
  • A lunch is eaten, but an image can be run again and again.

HOOK

Card, steps, shelf, lunch.

TELL A FRIEND

A recipe card for a lunch box.

OFTEN MIXED UP WITH Docker from zero: images, containers, ports and volumes for testers. That topic runs a ready-made container. This one builds your own image from a Dockerfile.

PRACTISE AND KEEP

Sources for this topic — 5 sources
  1. Market practice

    Writing a Dockerfile (Docker documentation) ↗ — Docker · Docker docs: a Dockerfile starts with FROM to pick a base image, COPY brings in files from the build context, RUN runs commands while the image is built, CMD sets the start command, and docker build with the t option names the image

    The Docker guide on Dockerfiles: the first line picks the base image, one instruction brings in files from the build context, another runs commands at build time, and the last sets the start command. The docker build command with the t option names the image. · Checked 2026-10-31

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  2. Market practice

    Understanding image layers ↗ — Docker · Filesystem diffs and shared image layers; not every configuration history entry creates a layer.

    Filesystem diffs and shared image layers; not every configuration history entry creates a layer. · Checked 2026-11-06

    Actual primary documentation body read during the complete V30 domain analysis before implementation. Live documentation access-dated; no claim this version is installed in the learner environment. No artwork copied by this content change.

  3. Market practice

    OCI Image Specification — image configuration ↗ — Open Container Initiative · history empty_layer and metadata-only history entries including CMD example.

    history empty_layer and metadata-only history entries including CMD example. · Checked 2026-11-06

    Actual primary documentation body read during the complete V30 domain analysis before implementation. Live documentation access-dated; no claim this version is installed in the learner environment. No artwork copied by this content change.

  4. Market practice

    Build context ↗ — Docker · Local/remote/named contexts, ordinary local COPY and COPY --from named-context exception.

    Local/remote/named contexts, ordinary local COPY and COPY --from named-context exception. · Checked 2026-11-06

    Actual primary documentation body read during the complete V30 domain analysis before implementation. Live documentation access-dated; no claim this version is installed in the learner environment. No artwork copied by this content change.

  5. Market practice

    Docker build best practices ↗ — Docker · Moving image tags versus digest-pinned identities; controlled updates.

    Moving image tags versus digest-pinned identities; controlled updates. · Checked 2026-11-06

    Actual primary documentation body read during the complete V30 domain analysis before implementation. Live documentation access-dated; no claim this version is installed in the learner environment. No artwork copied by this content change.

Deepest material on this page: L4 — Standards & sources. Where a topic stops short of implementation depth, that is a deliberate coverage decision, not an oversight — see coverage.