How to override Docker Compose settings?
· Category: Docker
Short answer
Docker Compose automatically reads docker-compose.override.yml to apply local overrides. You can also specify multiple files with -f to layer configurations for different environments.
Steps
- Create
docker-compose.override.ymlin the same directory. - Define only the keys you want to override.
- Run
docker compose upas usual; overrides are merged automatically.
Example
# docker-compose.yml
services:
web:
image: myapp
ports:
- "80:80"
# docker-compose.override.yml
services:
web:
ports:
- "8080:80"
volumes:
- ./src:/app/src
Start with a specific file:
docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d
Tips
- Use
docker compose configto view the merged configuration. - Keep the base file minimal and environment-specific settings in override files.
- Override files are ignored when explicit
-fflags are used.
Common issues
- YAML merging replaces entire arrays rather than appending; be careful with lists.
- Relative paths in override files are resolved from the override file location.
- Environment variables are merged, but explicit values in overrides take precedence.