Docker Compose allows using multiple files like docker-compose.yml and docker-compose.override.yml. What is the main benefit of using override files?
Think about how you can keep your base setup safe while customizing for different environments.
Override files let you customize or extend your base Compose setup without changing the original file. This helps keep your main configuration clean and reusable.
Given these two Compose files:
docker-compose.yml:
version: '3'
services:
web:
image: nginx
ports:
- "80:80"
docker-compose.override.yml:
version: '3'
services:
web:
environment:
- DEBUG=true
What is the output of docker-compose -f docker-compose.yml -f docker-compose.override.yml config?
Think about how Compose merges multiple files.
The config command merges all specified Compose files and shows the final configuration. Here, the override adds the environment variable to the web service.
You want to start only a subset of services defined in your Compose file based on the environment. Which Compose feature helps you do this?
Think about a way to tag services and choose which tags to run.
Profiles let you label services and start only those labeled with the selected profile using docker-compose --profile. This avoids editing files or using multiple files.
You use depends_on in your Compose file to start services in order. However, sometimes your app fails because the dependency is not ready. Why?
Think about the difference between a container running and the app inside being ready.
depends_on ensures containers start in order but does not check if the service inside is ready to accept connections. You need healthchecks or wait scripts for that.
In Docker Compose, what is the main advantage of using YAML anchors and extension fields (using & and *)?
Think about how you avoid copying the same text multiple times.
YAML anchors let you define a block once and reuse it multiple times with *. This reduces duplication and mistakes in Compose files.