On this page
The short answerWhat goes stale in a Dockerfile exampleLint before you buildBuild each Dockerfile from the docsRun each container and check the resultCheck the flags the docs nameKeep secrets out of the testInspect what you builtRun it on every changeChecklist for a Dockerfile example testWhere DocsAlive fitsWhat this does not replaceThe sources we checkedFAQDockerfile examples in docs tend to rot silently. A base image moves, a package is renamed, a flag changes, and the documented build fails for the next reader while the page still looks fine. The fix is to build and run every Dockerfile the docs show, on a clean machine, the same way you would test any other code example.
The short answer
Lint each Dockerfile first, because the cheap static checks catch the mistakes that make builds non-reproducible. Then build it in a clean environment with no cache and no local state to hide behind. Run the container and check the documented result — the health endpoint, the printed output, the listening port — not just the exit code. Compare the built image with what the docs claim about it. And keep the run honest: the build that only works because of a layer cached on the author's machine is exactly the build your reader does not have.
DocsAlive does not replace your Docker tooling. It runs the code samples in your Markdown docs — including the shell blocks around a Dockerfile, the build and run commands a reader copies — in a fresh container per page, and reports the ones that break. The Dockerfile checks on this page stay yours to run; the installation docs guide covers the wider setup path a reader follows before they ever reach a Dockerfile.
What goes stale in a Dockerfile example
- Base image tags: a floating tag such as
python:3orlatestchanges under the docs. The same Dockerfile builds a different image this month than last. - Package names: system packages get renamed or dropped between base image releases, so an
apt-get installline that worked last year fails now. - Build flags: flags are added, deprecated and occasionally removed between Docker and Buildx releases.
- Defaults: the default user, working directory or exposed port changes, and the run instructions in the prose no longer match the image.
A typical stale example combines two of these. The floating tag hides the package change until a reader's build pulls the new base:
FROM python:latest
RUN apt-get update && apt-get install -y libssl1.1
COPY app.py .
CMD python app.py
Nothing in this file is exotic, and every line is a future failure: the tag floats, the package name belongs to one Debian generation, the shell form of CMD changes how signals reach the process, and the versions are unpinned. The lint step below flags most of this before a build is even attempted.
Lint before you build
Start with hadolint, the Dockerfile linter. It reads the file without building it and reports the rules each line breaks:
hadolint Dockerfile
The rules that matter most for documentation examples are the reproducibility ones: DL3006 (always tag the version of an image explicitly), DL3007 (using latest is prone to errors and makes builds non-reproducible), DL3008 (pin versions in apt-get install), DL3013 (pin versions in pip install) and DL3025 (use JSON notation for CMD and ENTRYPOINT). Suppress a rule only with a reason recorded next to the suppression:
hadolint --ignore DL3006 Dockerfile
Docker itself also ships build checks. They were introduced in Dockerfile 1.8 and need Buildx 0.15.0 or later, and they run automatically as warnings during a normal build. To run only the checks — in a docs CI step, for example — use the --check flag, which exits with a non-zero status when a check fails:
docker build --check .
Where a warning should fail the published example outright, promote it with the check directive at the top of the Dockerfile, after the syntax directive:
# syntax=docker/dockerfile:1
# check=error=true
The check names worth knowing for docs work include JSONArgsRecommended, SecretsUsedInArgOrEnv (a secret passed as a build argument or environment variable ends up in the image history), UndefinedVar and CopyIgnoredFile (a COPY source excluded by .dockerignore — a classic reason a build works on the author's machine and fails for a reader who cloned the repo). Lint output belongs in the test record with the file and line, the same as any other docs finding.
Build each Dockerfile from the docs
- Copy the Dockerfile exactly as the docs show it, including any files it copies.
- Build it in a clean environment, for example
docker build --no-cache -t docs-test . - Record the exact failing step and error if the build breaks.
- Note any step that only works because of a local cache or a file outside the documented context.
Two flags keep the test honest. --pull fetches the current base image instead of reusing a stale local one, so a moved tag shows up in your run rather than your reader's. --no-cache forces every step to execute, which is slower and is the point: cached layers are where "works on my machine" lives. If the docs rely on a .dockerignore file, include it in the test context exactly as published, and if the docs never mention one, build without it — the reader will.
Multi-stage examples need the full build, not just the first stage. A common docs failure is a final stage that copies from a build stage by a name the example later renamed, or a runtime stage missing a library the build stage had. Build to the final stage, tag that image, and use it for the run test. Record the Docker and Buildx versions with the result: build checks and flag behaviour differ between releases, and a failure report without versions cannot be reproduced.
Run each container and check the result
- Run the built image with the exact command the docs give.
- Check the documented result: the port answers, the health endpoint returns success, or the printed output matches.
- Stop and remove the container after the check.
A container that starts is not a passing test. Check the thing the docs promise. If the guide says the service answers on a port, wait for the port rather than sleeping a fixed number of seconds, and then ask it the documented question:
docker run -d --name docs-test -p 8080:8080 docs-test
curl -sf http://localhost:8080/health
docker rm -f docs-test
If the container exits immediately, read its logs before changing anything: docker logs docs-test shows whether the failure is the image, the documented run command, or the environment the docs forgot to mention — an environment variable, a mounted file, a network the example assumes. Each of those is a different docs fix. Record which one it was; "the example failed" without the layer is a finding nobody can act on.
Check the flags the docs name
Compare the flags in the docs with the installed tool's own help output, for example docker build --help. Removed or renamed flags are a common break, and the help text of the version you test against is the reference — not release notes, and not memory. Where the docs support a range of Docker versions, say which versions the flags were checked against, and prefer flags that exist across the whole supported range.
The same applies inside the Dockerfile. Instruction behaviour changes between Dockerfile versions: the shell and JSON forms of CMD differ in how the process receives signals, which is why the linters push examples toward JSON form, and newer frontend versions add checks and directives that older ones ignore. An example that silently depends on a recent frontend should declare it with the # syntax= directive at the top of the file, so the reader's build uses the same frontend the test used.
Keep secrets out of the test
If a build needs a credential, use a throwaway value scoped to the test. Never bake a real key into the test image, and delete test images that contain one. An image layer keeps everything ever copied into it: deleting a secret in a later layer does not remove it from the earlier one, and docker history shows build arguments to anyone who pulls the image.
Where a build genuinely needs a secret — a private package registry token is the usual case — use a BuildKit secret mount instead of an ARG or ENV:
RUN --mount=type=secret,id=npm_token \
NPM_TOKEN=$(cat /run/secrets/npm_token) npm install
docker build --secret id=npm_token,env=NPM_TOKEN .
The secret is available during that one build step and is not recorded in the image. If your docs currently show the ARG pattern for credentials, that is a finding in its own right: the SecretsUsedInArgOrEnv build check exists because the pattern leaks, and the documented fix is the mount above.
Inspect what you built
After a passing build and run, compare the image with the claims the docs make about it. docker image inspect docs-test reports the exposed ports, the default command, the environment and the working directory the image actually carries. If the guide says the container listens on 8080 as a non-root user with a health check, the inspect output is where each of those claims is confirmed or contradicted:
docker image inspect docs-test --format '{{json .Config}}'
docker history docs-test
Check the size too. Docs often promise a small final image for multi-stage examples; a final stage that accidentally copies the build toolchain is a docs bug the run test will never catch, because the container still works. docker history shows which layer added the weight, and the fix is usually a copy line that named the wrong source.
Run it on every change
- Pull requests that touch docs or Dockerfiles: lint, then build and run the affected examples.
- Releases: build and run every Dockerfile example.
- Nightly: rebuild with
--pull, so base image changes surface even when nobody edited the docs.
A minimal CI outline:
# 1. Static checks
hadolint Dockerfile
docker build --check .
# 2. Honest build
docker build --pull --no-cache -t docs-test .
# 3. Documented result, not just a start
docker run -d --name docs-test -p 8080:8080 docs-test
curl -sf http://localhost:8080/health
docker rm -f docs-test
Record the base image digest each run resolves to, alongside the Docker version. When a nightly build breaks and the Dockerfile has not changed, the digest is the evidence that the base moved — the difference between "our docs broke" and "upstream changed," which have different owners.
Checklist for a Dockerfile example test
| Check | Evidence to retain |
|---|---|
| Dockerfile lints clean | hadolint output, with any suppression and its reason |
| Docker build checks pass | docker build --check output for the tested version |
| Clean build succeeds | Build log from a --pull --no-cache run, with tool versions |
| Container produces the documented result | The probe used — health response or output — not just an exit code |
| Flags checked against installed help | Tool version the flags were verified against |
| Image matches the docs' claims | Inspect output for ports, user, command and size |
| No secrets in the image | Secret mounts used for credentials; test images deleted |
| Base image digest recorded | Digest resolved by the run, so upstream moves are provable |
Where DocsAlive fits
DocsAlive runs the code samples in your docs in an isolated container on each release and nightly, separates likely docs bugs from expected failures, and can draft the fix for your team to review. For a docs page, that includes the shell sequence around the Dockerfile — the clone, build and run commands a reader copies in order — which is where out-of-date flags, renamed files and missing setup steps actually surface.
For a starting point, the free health check lets you send a public repository you own or maintain; the team runs the engine on up to 40 of its docs pages and emails the real report within 2 business days; the checkout is deleted after the run. Pricing is Open source $0/month, Team $299/month, Growth $699/month, and Scale from $1,499/month.
What this does not replace
DocsAlive does not lint your Dockerfiles, scan your images for vulnerabilities, or replace your image build pipeline. Keep hadolint and the Docker build checks for the file, your scanner for the image, and your own review for whether the prose explains why the example is shaped the way it is. A container that starts also does not prove it is secure, small or production-ready — those are separate reviews with separate tools.
The sources we checked
| Source | What it covers |
|---|---|
| Docker build checks documentation | The --check flag, the check directive, and the named build checks |
| hadolint rule reference | DL3006, DL3007, DL3008, DL3013 and DL3025 and what each one guards |
| Docker build documentation | BuildKit secret mounts and the --secret flag |
| Docker CLI reference | Build, run, inspect and history flags used in this guide |
FAQ
Is a successful build a passing test?
No. A build proves the image assembles. The run test — the documented port, health endpoint or output — proves the image does what the docs say it does. Most stale examples fail at one of the two; you need both to know which.
Why build with --no-cache if it is slower?
Because the cache is the difference between your machine and the reader's. A step that only succeeds from a cached layer fails for every first-time reader. Use the cache in development; drop it in the test that stands in for the reader.
Should docs pin base images to a digest?
Pinning to a digest is the most reproducible option and the hardest to read. A specific version tag is the usual compromise for examples, as long as a nightly --pull build watches the tag for changes. What the linters flag — and readers suffer from — is the floating latest.
Does DocsAlive build my Dockerfiles?
It runs the code samples in your Markdown docs in a fresh container and reports the blocks that break, including the build and run commands shown on the page. Dedicated Dockerfile linting and image scanning stay with your Docker tooling.
How often should Dockerfile examples be rebuilt?
On pull requests that touch them, in full at release, and nightly with --pull — base images change on their own schedule, not yours.




