Build and test an image in CI
Continuous integration (CI) automatically checks changes before they become release candidates. Continuous delivery keeps a verified artifact ready for release; continuous deployment additionally deploys automatically when its gates pass. For Docker, a useful pipeline starts by building an image, running the application inside it, and checking an observable result. A successful image build alone does not test the application.
Worked example
Work offline: the scenarios and evidence are synthetic. Do not run hosted workflows, contact registries, use real credentials or deploy anything for this lesson. Keep the exercise offline. Before any separately authorized runtime check, verify the effective daemon, builder, runner or deployment identity as applicable; use synthetic data, reviewed inputs and bounded resources. Record missing evidence as NOT RUN.
name: Container smoke-test example"on": workflow_dispatch:permissions: {}jobs: smoke: runs-on: ubuntu-latest timeout-minutes: 5 steps: - name: Build and verify a toy image shell: bash run: | set -euo pipefail work=$(mktemp -d) trap 'rm -rf -- "$work"' EXIT cd "$work" printf 'FROM busybox:1.36\nCMD ["echo", "bytemind-ok"]\n' > Dockerfile docker build --tag bytemind-ci:demo . test "$(docker run --rm --network none bytemind-ci:demo)" = bytemind-ok docker image rm bytemind-ci:demoThis staged GitHub Actions example is self-contained: it creates a tiny Dockerfile in a temporary directory, builds a named image, and checks its standard output. set -euo pipefail and test make a failed command or mismatched output fail the step. The example uses a mutable public base tag, and a real run may fetch it; this is not a reproducible or offline Docker build. The named image is removed on success; a failed step may leave it until the ephemeral runner is discarded. The example has no checkout action, publishing, credentials, or deployment. Run only on a fresh authorized ephemeral runner after reviewing the base digest, runner label and cost. Never copy it into a live workflow merely to complete the lesson. For real applications, build the reviewed source commit and run meaningful unit, smoke and integration tests; test each supported architecture independently before promotion. The staged workflow is an online illustration, not an offline lab command: the build can retrieve its base and the run uses the default pull policy. A failed build must never authorize testing a stale tag. In a separately reviewed real workflow, record the successful build output identity, verify the local image, use an explicit no-pull test against that identity, and retain exit status and output. The temporary directory and image tag must belong solely to the authorized disposable runner.
Common mistake
Building with no error does not prove the configured command can start or produce the desired output. Keep the release blocked until runtime assertions pass.
Manual practice
Without running the workflow, change the expected output to wrong on paper. Identify the failing line and explain why publishing must not follow it. Design a second assertion for a real CLI application.
Worksheet: lab-fixtures/docker-ci-cd/01-build-test-workflow/scenario.txt.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Build and test an image in CI — Knowledge check
Apply release and CI/CD reasoning to a fictional scenario.
What does a passed Docker build demonstrate?
In the staged workflow, the container exits successfully but prints wrong instead of bytemind-ok. What happens to the assertion?
Why is busybox:1.36 not a reproducibility guarantee?