Keep the shared setup in compose.yaml, and put development-only settings in compose.override.yaml.
When you run docker compose up without -f, Compose merges the override file automatically. So developers get these by default:
- bind mounts (your local source folder mounted into the container)
- a dev command, for example with live reload
- extra ports, such as a debug port
For other environments, pass the files yourself with -f. For example: docker compose -f compose.yaml -f compose.prod.yaml up. Compose merges files in order, so later files override earlier ones.
For optional services, such as an admin UI or a mail catcher, use profiles. Those services only start when you turn on their profile with --profile.
Keep secrets out of all these files. Inject them from the environment instead.
compose.override.yamlis merged automatically.- Use
-fto choose the files and their order yourself. - Later files override earlier ones.
- Use
profilesfor optional services.
Read more