0
0
Dockerdevops~20 mins

Multiple Compose files (override) in Docker - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Compose Override Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
Output of Docker Compose with override file
Given two Docker Compose files, 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=production

docker-compose.override.yml:
services:
  app:
    environment:
      - MODE=development


Command run: docker compose up
AMODE=development
BMODE=production,MODE=development (both set)
CMODE=production
DNo MODE environment variable set
Attempts:
2 left
💡 Hint
Override files merge and override keys, environment variables in override replace the original.
Configuration
intermediate
1: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?
A
services:
  web:
    ports:
      - 8080:80
B
services:
  web:
    ports:
      - "8080:80"
C
services:
  web:
    ports:
      - 80:8080
D
services:
  web:
    expose:
      - "8080"
Attempts:
2 left
💡 Hint
Ports must be strings with quotes and format hostPort:containerPort.
Troubleshoot
advanced
2:00remaining
Why does the override file not change the command?
You have this base Compose file snippet:
services:
  app:
    image: myapp
    command: run-server

And this override snippet:
services:
  app:
    command: run-debug

After running docker compose up, the container still runs run-server. What is the most likely reason?
AThe override file is not named correctly or not detected by Docker Compose
BThe command key cannot be overridden in Compose override files
CDocker Compose caches the command and ignores overrides
DThe image 'myapp' has an entrypoint that ignores the command
Attempts:
2 left
💡 Hint
Check the file names and how Docker Compose loads override files automatically.
🔀 Workflow
advanced
2: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?
Adocker compose -f docker-compose.override.yml -f docker-compose.prod.yml up
Bdocker compose up -f docker-compose.override.yml -f docker-compose.prod.yml
Cdocker compose -f docker-compose.yml -f docker-compose.override.yml -f docker-compose.prod.yml up
Ddocker compose up --override-files docker-compose.override.yml docker-compose.prod.yml
Attempts:
2 left
💡 Hint
Use multiple -f flags with the base file first, then overrides in order.
Best Practice
expert
2: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?
APass sensitive variables as command line arguments when running docker compose up
BHardcode sensitive variables directly in the override Compose file for production
CInclude sensitive variables in the base Compose file but encrypt the file in version control
DStore sensitive variables in a separate .env file and reference it in the override file, which is excluded from version control
Attempts:
2 left
💡 Hint
Use environment files and .gitignore to keep secrets safe.