Docker in a pipeline: build the image, run the tests inside it and keep the report
Build the test image in a pipeline, run the tests inside it, reuse cached layers, keep secrets out of the image and save the report folder.
L1–L4 are part of the Pro pass
L0 Explain simply
Analogy: packing a suitcase in layers. Things that rarely change go at the bottom. Things that change every trip go on top. Next time you pack only the top again. The house key does not go in the suitcase. You carry the key in your pocket for the journey, and you bring the receipts home in a folder.
The bottom layers are the cache. The top layer is the test code. The key in the pocket is a runtime secret. The receipts are the report folder.
Leo, a developer at Daily List, a to-do list app, packs the test image for the pipeline. Mei needs the report after the container stops.
What it is: This topic is Docker inside (CI), where the shared build makes an image and runs the tests in it. The reuses unchanged build steps. A report folder bind mount shares a host folder so the report outlives the container. A build secret mount exists only during the build, not when the container starts. GitHub Actions without Docker is the neighbour, and it uses the runner's own system.
Why it matters: Daily List tests should see the same (OS) and the same packages on every run. The cache keeps rebuilds shorter. The report mount keeps the JUnit XML (Extensible Markup Language) after the container exits. A test token must not be baked into an image that might be pushed. BuildKit secrets do not solve a key the tests need at run time.
PLAIN WORDS · 6 in this section
- runtime
- the time when a program is actually running
- reuses
- uses again
- outlives
- lasts longer than
- github
- a web site that hosts code and runs checks
- junit
- a file format for test results
- extensible
- able to be added to later
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 Packing a suitcase in layers and leaving the house key at home.
- Bottom
- Top
- Key
HOW THE PICTURE MAPS
| In the picture | In the software |
|---|---|
| Shoes at the bottom | Steps that change least |
| Clothes on top | The test code |
| The key left at home | A secret kept out of the image |
| A bag you carry out | The shared report folder |
WHERE THIS PICTURE STOPS
- A suitcase has a size limit, but an image can grow large.
- Packing the top again is quick, yet one change low down means packing again above it.
- The bag carried out is yours alone, while a shared folder can write to the host.
HOOK
Shoes below, clothes above, key at home.
TELL A FRIEND
Pack the stable things first and keep the key home.
OFTEN MIXED UP WITH Docker part 2: write a Dockerfile and build your own test image. That topic writes a Dockerfile for a test image. This one builds and runs it in a pipeline, with cache, secrets and a saved report.
PRACTISE AND KEEP
Sources for this topic — 3 sources
- Market practice
Build cache invalidation (Docker documentation) ↗ — Docker · Docker docs on the build cache: steps are checked in order, and after one miss every later step is built again, so put steps that change least first
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.
- Market practice
Build secrets (Docker documentation) ↗ — Docker · Docker docs on build secrets: build arguments and environment variables are not suitable for secrets, and a secret mount keeps the secret out of the image
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.
- Market practice
Bind mounts (Docker documentation) ↗ — Docker · Docker docs on bind mounts: the volume option takes a host path, then a container path, so files the container writes appear on the host
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.
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.