Compose profiles for optional services
Profiles select optional services without maintaining a second full project. The worker has no profile and is part of the normal application. The reporter belongs to the tools profile. Enabling tools adds it to the set of active services; explicitly targeting a profiled service also activates it and its declared dependencies for that operation, not every service with the same profile. Profiles are operational selection, not access control or a security boundary. Keep indispensable services unprofiled unless the dependency design explicitly requires otherwise.
Read the configuration
services: worker: image: busybox:1.37 pull_policy: never user: 10001:10001 command: - sh - -c - exec sleep 300 network_mode: none reporter: image: busybox:1.37 pull_policy: never user: 10001:10001 command: - sh - -c - echo report-ready; exec sleep 300 network_mode: none profiles: - toolsManual 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/08-profiles/ in the extracted archive and run from a disposable copy of that folder.
docker compose -f compose.yaml -p bm-v13-profiles config --quietdocker compose -f compose.yaml -p bm-v13-profiles up -d --no-build --pull neverdocker compose -f compose.yaml -p bm-v13-profiles --profile tools ps -adocker compose -f compose.yaml -p bm-v13-profiles --profile tools up -d --no-build --pull neverdocker compose -f compose.yaml -p bm-v13-profiles --profile tools psNormal up should start worker only. Enabling tools should add reporter. Inspect ps after each step and use the tools profile again during cleanup so optional services are included. Use ps -a with the tools profile to check that reporter is absent before activation, not merely stopped. Check the original worker ID is retained after tools is enabled.
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-profiles --profile tools downdocker compose -f compose.yaml -p bm-v13-profiles --profile tools ps -aCommon mistake
Using a debug profile does not protect the debug service from authorized operators who can activate it. Do not put dangerous defaults or public admin ports in optional profiles.
Manual practice
Predict the active services with tools disabled and enabled. Add a second harmless optional service on paper and reason about explicitly targeting reporter.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Compose profiles for optional services — Knowledge check
Reason about the Compose configuration and its consequences.
Which service starts with default up?
What activates reporter along with worker?
Are profiles access-control rules?