Build and package the application
Worked example
This is an offline lesson. Data are fictional and Docker commands are unexecuted. Any optional execution requires an authorized disposable VM, a verified context, synthetic data, restricted access and no external transmission. Do not collect secrets or private output. Before any separately authorized Docker query, verify the effective endpoint and builder (including environment overrides), not just the context name. Use only disposable lab resources; a failed check is a stop condition, not permission to retry against a different host.
Reference files: Dockerfile, .dockerignore, app.py, proxy.py, db.pyBase: approved local Python 3.12-compatible Linux image (lab tag).check stage: parse source; runtime: COPY --from=check, USER 10001:10001.Staged build (authorized offline VM only):docker build --network none -t bytemind-notes:lab-v1 .Record base identity, context, build log and local image ID.Do not treat the lab tag as a registry digest.The check stage parses each source file; this catches syntax errors but not functional bugs. The local unit and HTTP tests are a separate step. The final image uses an explicit numeric runtime user and creates an owned /data directory for a fresh named volume. An existing volume may have different ownership; verify it and plan a targeted migration instead of weakening permissions. A lab tag is a mutable reference. For reproducible release builds record approved platform-specific base digest, source revision, builder and configuration, and verify the resulting artifact. The example uses a local base alias rather than fabricating a digest. A network-none RUN setting does not guarantee that the builder cannot contact registries; confirm the entire VM is offline and the builder already has access to the base. The allowlist in .dockerignore includes only the Dockerfile and three source files. Verify the base in the selected builder, including root privileges for the check/runtime setup and required Python/SQLite functionality. Stop on build failure; do not test a stale tag. The source parse stage is not the test suite.
Common mistake
Parsing source is not equivalent to testing behavior; nor does a multi-stage build automatically create a small or secure image.
Manual practice
Complete the starter Dockerfile TODOs, check the context allowlist, and write an image evidence record. In an approved VM only, compare the resulting ID and runtime user with your expectation.
Worksheet: lab-fixtures/docker-professional-capstone/02-packaging/scenario.txt. Project: lab-fixtures/docker-professional-capstone/project/.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Build and package the application — Knowledge check
Interpret capstone evidence and make a safe operational decision.
What does the check stage demonstrate?
What is necessary for stable base identity?
How should an existing mismatched volume owner be handled?