Sub topic 2
Checking the Merged Compose Configuration
Assume you know basic Docker images, containers, YAML, environment variables, and docker compose up. This chapter focuses on how Compose decides which services and settings to use.
Inspecting the merged result
Compose can combine several files before creating containers. The config command renders that final configuration without starting services:
docker compose -f compose.yaml -f compose.prod.yaml configThe files are read from left to right. Later files override or extend earlier files. Variable expressions are also resolved. This makes config the first diagnostic step when a container has an unexpected port, command, image, or environment variable.
You can inspect only the service names:
docker compose -f compose.yaml -f compose.prod.yaml config --servicesThis is useful in scripts and confirms which services are available under the selected files and profiles.
Putting optional services in profiles
A service with no profiles key starts normally. A service with a profiles key starts only when that profile is active.
services:
web:
image: example/web:1.0
adminer:
image: adminer
profiles: [debug]
ports:
- "8080:8080"
migrate:
image: example/web:1.0
command: ["python", "manage.py", "migrate"]
profiles: [tools]Here, web always starts. adminer and migrate are optional. Profiles are useful for tools that should exist in development or during a one-time task, but should not run in every environment.
Activating profiles
Activate a profile with --profile:
docker compose --profile debug up -dYou can activate several profiles with the COMPOSE_PROFILES environment variable:
COMPOSE_PROFILES=debug,tools docker compose up -dA command that names a profiled service activates that service's profile for the command:
docker compose run --rm migrateUse config with the same selection to verify it:
docker compose --profile debug config --servicesExercise
Which command starts the default services and the debug profile?
Show answer
docker compose --profile debug up -d