Compose overrides and file merge order
Compose can combine a base file and an override file. Specify files with -f in the intended order. In the base, worker has BM13_MODE=base and BM13_KEEP=yes; the override changes only BM13_MODE and adds BM13_EXTRA. Environment mapping keys merge, so KEEP survives. Single-valued fields can be replaced, while some lists are combined or use resource-specific uniqueness rules. Do not assume every sequence is replaced. Relative paths in the ordinary multiple-file merge are interpreted from the base file directory, not independently for each fragment. Interpolation is applied to individual files before merging. The example uses explicit -f order and a common base directory; project-directory overrides can change the path base.
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_MODE: base BM13_KEEP: 'yes'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/09-overrides/ in the extracted archive and run from a disposable copy of that folder.
docker compose -f compose.yaml -p bm-v13-overrides configdocker compose -f compose.yaml -f review.yaml -p bm-v13-overrides configdocker compose -f compose.yaml -f review.yaml -p bm-v13-overrides up -d --no-build --pull neverdocker compose -f compose.yaml -f review.yaml -p bm-v13-overrides exec -T worker printenv BM13_MODEdocker compose -f compose.yaml -f review.yaml -p bm-v13-overrides exec -T worker printenv BM13_KEEPdocker compose -f compose.yaml -f review.yaml -p bm-v13-overrides exec -T worker printenv BM13_EXTRAThe base model should show mode base. The combined model should show review, yes and extra. Starting with both files should deliver those three synthetic settings to worker. No real credentials belong in rendered config.
Clean only this disposable project. No global prune or force removal. Verify the project is empty. Retain the base image.
docker compose -f compose.yaml -f review.yaml -p bm-v13-overrides downdocker compose -f compose.yaml -f review.yaml -p bm-v13-overrides ps -aCommon mistake
Using the override alone can omit required fields. Always inspect the merged model and use the same file order for subsequent lifecycle commands.
Manual practice
Predict what remains if the override contains only BM13_EXTRA. Verify with config and explain why merge rules are safer to inspect than to guess.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Compose overrides and file merge order — Knowledge check
Reason about the Compose configuration and its consequences.
Which mode is selected with the override?
What happens to BM13_KEEP?
Where are normal multi-file relative paths based?