Validate Compose configuration before deployment
Validation is a progression: YAML parsing checks syntax; docker compose config resolves the Compose model and checks configuration; a real run checks image availability, permissions and behavior. A syntactically valid file can still be an invalid Compose model. The sample requires BM13_REQUIRED using the non-empty required expression. Provide a harmless value and validate quietly. The second deliberately invalid invocation uses an empty value and should fail before containers are created. Inspect only synthetic rendered values. config --services helps confirm service names but cannot prove network or application health.
Read the configuration
services: worker: image: busybox:1.37 pull_policy: never user: 10001:10001 command: - sh - -c - exec sleep 300 network_mode: none environment: BM13_REQUIRED: ${BM13_REQUIRED:?provide synthetic value}Manual lab
Manual lab only, not browser execution. Use a fresh approved disposable Linux VM with external egress blocked and a local Docker context. Check docker context show, docker version and docker compose version; verify support for each flag and field. Preload and verify the native-platform BusyBox 1.37 digest, entrypoint and required applets; the tag is mutable. Ensure bm-v13 project/image/volume names are unused and no inherited COMPOSE_PROFILES or BM13 variables interfere. Use only the synthetic files here, on a disposable copy. File-backed config/secret mounts are limited to these exact files; verify UID 10001 can read them. No public ports, external pulls/pushes, real secrets or host directory mounts. Run each command individually; stop on unexpected failures, perform scoped cleanup and dispose of the VM. Explicit negative probes are expected to fail. All results below are predictions. Before Engine requests, verify the effective endpoint including DOCKER_HOST and DOCKER_CONTEXT; a project name does not select the daemon. Review inherited COMPOSE_ENV_FILES, COMPOSE_DISABLE_ENV_FILE, profile and project settings. Use a clean shell and the exact fixture directory. Inspect only synthetic config, logs and files. If a build is required, verify the effective builder can resolve the approved local base without egress; stop if build fails, never reuse a stale tag.
Open lab-fixtures/docker-compose-configuration/10-config-validation/ in the extracted archive and run from a disposable copy of that folder.
BM13_REQUIRED=approved docker compose -f compose.yaml -p bm-v13-config-validation config --quietBM13_REQUIRED=approved docker compose -f compose.yaml -p bm-v13-config-validation config --services# Expected nonzero exit: required variable is emptyBM13_REQUIRED= docker compose -f compose.yaml -p bm-v13-config-validation config --quietWith BM13_REQUIRED=approved the quiet validation should succeed. With an empty value it should return a nonzero exit status; the exact error text is not asserted. This lab deliberately stops at configuration inspection and creates no resources. First require a successful positive command and the service name worker. Capture the negative exit code immediately and inspect the diagnostic to confirm it concerns BM13_REQUIRED, not a missing file or unavailable Compose executable. A YAML parser alone cannot test interpolation.
Common mistake
Never call valid YAML a successful deployment. Do not use rendered config containing real secrets as a public troubleshooting attachment.
Manual practice
Write a release checklist with separate evidence for syntax, model validation, runtime health, intended connectivity and cleanup. Mark the unexecuted steps NOT RUN.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Validate Compose configuration before deployment — Knowledge check
Reason about the Compose configuration and its consequences.
What does successful YAML parsing prove?
With the required-variable expression in this fixture, why should the empty-value invocation fail?
What should be checked after config succeeds?