Compose configs and secrets as files
Configs deliver ordinary configuration files; secrets deliver sensitive values through explicitly granted file mounts rather than ordinary environment variables. Both require a top-level definition and a service grant. The Linux short syntax mounts the config at /settings and the secret at /run/secrets/demo_token. Only reader receives the secret. This local Compose fixture uses two harmless text files and no real credentials. File-backed mounts in local Compose may rely on host file permissions, so verify read access and do not assume orchestrator-grade encryption, identity mapping or secret rotation. A service can still leak a secret if its application prints it.
Read the configuration
services: reader: image: busybox:1.37 pull_policy: never user: 10001:10001 command: - sh - -c - exec sleep 300 network_mode: none configs: - settings secrets: - demo_token observer: image: busybox:1.37 pull_policy: never user: 10001:10001 command: - sh - -c - exec sleep 300 network_mode: noneconfigs: settings: file: ./settings.txtsecrets: demo_token: file: ./demo-token.txtManual 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/05-configs-secrets/ in the extracted archive and run from a disposable copy of that folder.
Both supplied files are intentionally harmless, normally readable test fixtures; never copy real tokens into this directory. Local file mounts may preserve host ownership.
docker compose -f compose.yaml -p bm-v13-configs-secrets config --quietdocker compose -f compose.yaml -p bm-v13-configs-secrets up -d --no-build --pull neverdocker compose -f compose.yaml -p bm-v13-configs-secrets exec -T reader cat /settingsdocker compose -f compose.yaml -p bm-v13-configs-secrets exec -T reader test -r /run/secrets/demo_tokendocker compose -f compose.yaml -p bm-v13-configs-secrets exec -T observer test ! -e /run/secrets/demo_tokenReader should print the harmless configuration and pass a readability test for the synthetic secret without printing its value. Observer should pass the absence test. File permissions and actual mount behavior remain untested. Check both containers are running, the grant and mount metadata match the reviewed model, and the absence test runs inside observer. Absence of the path does not prove that the value is inaccessible through every other channel. Do not print secret content or inspect unrelated environment variables.
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 -p bm-v13-configs-secrets downdocker compose -f compose.yaml -p bm-v13-configs-secrets ps -aCommon mistake
Adding a top-level secret does not grant all services access. Do not commit real file-backed secrets to Git or expose them in diagnostic output.
Manual practice
Explain which source file and service grant control each mount. Compare the reader and observer results without reading or printing the secret contents.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Compose configs and secrets as files — Knowledge check
Reason about the Compose configuration and its consequences.
Which service receives demo_token?
Where is the short-syntax Linux secret mounted?
Does a local secret mount guarantee encrypted storage?