🐳 Docker Intermediate

What is Docker Compose override and multiple Compose files?

Why Interviewers Ask This

This tests whether you can apply Docker knowledge to real-world scenarios. Interviewers are looking for clarity of thought and evidence that you've encountered this in production code.

Answer

Docker Compose supports multiple configuration files that are merged together, enabling environment-specific configurations without duplicating the base configuration. Override files: docker-compose.override.yml is automatically merged with docker-compose.yml when you run docker compose up without specifying files. This is typically used for development-specific overrides (volume mounts for live code reloading, debug ports, additional env vars). Multiple -f files: docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d — merges the files in order. Later files override earlier ones for scalar values; lists (volumes, ports, environment) are merged/appended. Common pattern: docker-compose.yml — base service definitions; docker-compose.override.yml — development overrides (automatically loaded); docker-compose.prod.yml — production overrides (explicitly specified); docker-compose.test.yml — test environment configuration. Merging rules: string values are replaced by the later file; lists are concatenated. Create a merged output: docker compose -f docker-compose.yml -f docker-compose.prod.yml config — outputs the merged YAML without running anything. Use COMPOSE_FILE env var to set default file list.

Pro Tip

Demonstrate both theoretical understanding and practical experience. Say what it is, then give an example of how you actually used it in a Docker codebase.