Challenge - 5 Problems
Compose Override Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate1:30remaining
Output of Docker Compose with override file
Given two Docker Compose files,
docker-compose.yml:
docker-compose.override.yml:
Command run:
docker-compose.yml and docker-compose.override.yml, what will be the value of the environment variable MODE in the running container?docker-compose.yml:
services:
app:
image: myapp:latest
environment:
- MODE=productiondocker-compose.override.yml:
services:
app:
environment:
- MODE=developmentCommand run:
docker compose upAttempts:
2 left
💡 Hint
Override files merge and override keys, environment variables in override replace the original.
✗ Incorrect
Docker Compose merges the override file on top of the base file. The environment variable MODE in the override file replaces the one in the base file, so the container runs with MODE=development.
❓ Configuration
intermediate1:30remaining
Correct syntax to override ports in Compose override file
You have a base
docker-compose.yml with a service exposing port 80. You want to override it in docker-compose.override.yml to expose port 8080 instead. Which override snippet correctly replaces the port mapping?Attempts:
2 left
💡 Hint
Ports must be strings with quotes and format hostPort:containerPort.
✗ Incorrect
The correct syntax uses quotes around the port mapping string and specifies host port first, then container port. Option B correctly overrides the port mapping to expose container port 80 on host port 8080.
❓ Troubleshoot
advanced2:00remaining
Why does the override file not change the command?
You have this base Compose file snippet:
And this override snippet:
After running
services:
app:
image: myapp
command: run-serverAnd this override snippet:
services:
app:
command: run-debugAfter running
docker compose up, the container still runs run-server. What is the most likely reason?Attempts:
2 left
💡 Hint
Check the file names and how Docker Compose loads override files automatically.
✗ Incorrect
Docker Compose automatically loads
docker-compose.override.yml if it exists. If the override file is named differently or not in the current directory, it won't be applied, so the command remains unchanged.🔀 Workflow
advanced2:00remaining
Using multiple override files in Docker Compose
You want to run Docker Compose with two override files:
docker-compose.override.yml and docker-compose.prod.yml. Which command correctly applies both overrides with the base docker-compose.yml?Attempts:
2 left
💡 Hint
Use multiple -f flags with the base file first, then overrides in order.
✗ Incorrect
Docker Compose merges files in the order they are specified with -f flags. The base file must be first, followed by override files. Option C correctly specifies all three files in order.
✅ Best Practice
expert2:30remaining
Best practice for sensitive data in multiple Compose files
You have a base Compose file and an override file for production. You need to keep sensitive environment variables out of version control but still use them in production. What is the best practice?
Attempts:
2 left
💡 Hint
Use environment files and .gitignore to keep secrets safe.
✗ Incorrect
The best practice is to keep sensitive data in a separate .env file that is referenced by the override Compose file and excluded from version control. This keeps secrets out of code and allows safe overrides.