Sub topic 14
Troubleshooting common surprises
This chapter assumes you can write a base file and an override file, select files with -f, and put services in profiles. It covers the cases where the result differs from what you expected, and how to find the cause.
Start with the merged result
Most surprises come from the merge, not from the individual files. Before you edit anything, print the final configuration.
# What the files merge into, with variables filled in
docker compose -f compose.yaml -f compose.prod.yaml config
# Which services a given profile would start
docker compose --profile debug config --servicesIf the output is wrong, the problem is in file selection or merging. If the output is right but the containers are wrong, the problem is in what is already running.
Common symptoms
| Symptom | Likely cause | Fix | Column |
|---|---|---|---|
| Development settings vanish in production | `-f` stops Compose from loading `compose.override.yaml` | List every file you want, in order | |
| `COMPOSE_FILE` seems ignored or split wrongly | The separator is `:` on Linux and macOS, `;` on Windows | Use the right separator, or set `COMPOSE_PATH_SEPARATOR` | |
| Both `8000:8000` and `9000:8000` are published | Lists such as `ports` are appended | Use `ports: !override` in the later file | |
| A service never starts | Its profile is not active | Use `--profile`, `COMPOSE_PROFILES`, or name the service in `run` | |
| Error: `required variable DB_PASSWORD is missing a value` | The `:?` form of interpolation found no value | Export the variable or add it to an env file | |
| A `.env` value is not used | A variable in your shell takes precedence over `.env` | Run `env \ | grep NAME` and unset the shell variable |
| Relative paths point to the wrong place | Paths resolve against the first file's directory | Keep files together, or set `--project-directory` |
Profiles and dependencies
A service without a profile can depend on a service that has one. If the profile is inactive, Compose reports an error or leaves the dependency out. The fix is to avoid that dependency. Either give both services the same profile, or move the dependency to a service that always runs.
Profiles also affect shutdown. Plain docker compose down only handles services that are active, so a container started under debug can stay behind.
# Stop and remove everything, including profiled services
docker compose --profile debug down
# Or remove containers for services no longer in the file
docker compose down --remove-orphansOld state, not old config
If config looks right but the app behaves like the old setup, check for stale containers. Compose only recreates a container when its configuration changed. A changed mounted source file or a rebuilt image tag may not trigger that.
docker compose ps -a
docker compose up -d --build --force-recreateNamed volumes survive down. A database that ignores a new POSTGRES_PASSWORD was probably initialized with the old one. Remove the volume with docker compose down -v only when you are sure the data is disposable.
A short checklist
- Run
docker compose configwith the exact flags and environment you use forup. - Confirm which files were loaded, and in what order.
- Look for list fields (
ports,volumes) that gained entries instead of being replaced. - Run
config --serviceswith each profile you expect to be active. - Compare shell variables with
.envvalues. - Check
docker compose ps -afor leftover containers.
Exercise
You run docker compose -f compose.yaml -f compose.prod.yaml up -d. The web service still publishes port 5678 and mounts ./src, although only compose.override.yaml defines those settings. What is the most likely cause, and how do you confirm it?
Show answer
An older container from a plain docker compose up -d is still running, because Compose reuses a container whose configuration has not changed for that service. Confirm by running docker compose -f compose.yaml -f compose.prod.yaml config. If the output has no 5678 port and no ./src volume, the files are correct and the old container is the problem. Run docker compose down, then start again, or use up -d --force-recreate.