What is docker-compose.override.yml and how is it used?
Compose automatically merges docker-compose.override.yml on top of docker-compose.yml. Teams keep shared settings in the base file and development extras like bind mounts or debug ports in the override.
Explain it simply
The base file is the standard thali menu. The override is the 'extra chilli, no onion' note: same meal, tweaked for one person.
When you run docker compose up with no -f flag, Compose reads docker-compose.yml and then docker-compose.override.yml, merging them. Single values are replaced, lists such as ports are combined, and mappings such as environment are merged by key. For production you often skip the override by naming files explicitly: docker compose -f docker-compose.yml -f docker-compose.prod.yml up. Later files win.
This keeps production settings clean while letting developers mount source code and use debug flags without editing shared files.
Example
# docker-compose.yml
services:
web:
image: myapp:1.4
# docker-compose.override.yml (dev only)
services:
web:
build: .
volumes:
- ./src:/app/src
ports:
- "9229:9229" # debuggerWhat to say in the interview
"Compose merges docker-compose.override.yml onto the base file automatically, so I put dev-only settings there. For other environments I pass files explicitly with multiple -f flags, later ones winning."
Common mistakes
- Shipping dev bind mounts to production because the override was picked up automatically.