CodePark/ questions / Docker Compose
START PRACTICINGPRACTICE
Backend question · Docker › Docker Compose

How would you keep one Compose setup for development (live reload, debug port, bind-mounted source) without leaking those settings into other environments?

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.yaml is merged automatically.
  • Use -f to choose the files and their order yourself.
  • Later files override earlier ones.
  • Use profiles for optional services.