liveBook · Manning

Test stage

As explained in Learn Docker in a Month of Lunches, Second Edition

A multi-stage Dockerfile stage that runs tests against artifacts produced by an earlier stage.

A test stage is a named Dockerfile stage that receives artifacts from an earlier build stage, performs test-related commands, and can pass selected output to the final image. section 4.1

Use a test stage to:

  • Start from its own base image and toolset. section 4.1
  • Copy artifacts from the build stage with COPY --from. section 4.1
  • Run commands during the image build; a failed command fails the whole build. section 4.1
  • Expose only files explicitly copied into the final stage. section 4.1

Minimal test stage

FROM diamol/base:2e AS build-stage RUN echo 'Building...' > /build.txt FROM diamol/base:2e AS test-stage COPY --from=build-stage /build.txt /build.txt RUN echo 'Testing...' >> /build.txt FROM diamol/base:2e COPY --from=test-stage /build.txt /build.txt

How Learn Docker in a Month of Lunches, Second Edition covers it

How deep it goes
Explains stage isolation, cross-stage copying, sequential execution, and failure behavior without detailing real test frameworks.
Examples
Uses a Dockerfile that copies build.txt, appends a testing marker, and copies the result into the final stage.
What it assumes
Assumes basic Dockerfile familiarity while introducing named stages, COPY --from, and RUN during image builds.
What you can do after
Apply via Docker by building a sequential multi-stage Dockerfile and inspecting which artifacts reach the final image.
How it connects
Connects test stages with multi-stage builds, Dockerfile, build stages, final stages, COPY, and RUN.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Docker in a Month of Lunches, Second Edition. The section links point to the parts of the book it draws on.