0
0
Dockerdevops~20 mins

Compose profiles for selective services in Docker - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Compose Profiles Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of docker-compose with profile enabled
Given the following docker-compose.yml snippet, what will be the output of docker-compose --profile debug ps?
Docker
version: '3.9'
services:
  app:
    image: alpine
    command: sleep 1000
  debug:
    image: busybox
    command: sleep 1000
    profiles:
      - debug
ALists both 'app' and 'debug' containers running
BLists only 'app' container running
CLists only 'debug' container running
DNo containers are listed
Attempts:
2 left
💡 Hint
Profiles enable selective service activation; using --profile debug activates services tagged with 'debug' plus those without any profile.
Configuration
intermediate
2:00remaining
Enable a service only with a specific profile
Which of the following docker-compose.yml service definitions correctly enables the service monitor only when the profile monitoring is active?
A
monitor:
  image: prom/prometheus
  profiles:
    monitoring: true
B
monitor:
  image: prom/prometheus
  profiles:
    - monitoring
C
monitor:
  image: prom/prometheus
  profiles: monitoring
D
monitor:
  image: prom/prometheus
  profile: monitoring
Attempts:
2 left
💡 Hint
Profiles are defined as a list under the key 'profiles'.
Troubleshoot
advanced
2:00remaining
Why does a service not start with a profile?
You have a service defined with a profile 'test'. You run docker-compose up without specifying any profile. Why does the service not start?
AThe service requires environment variables to start
BThe service image is missing, so it cannot start
CThe service is disabled by default in docker-compose version 3.9
DServices with profiles only start if the profile is explicitly enabled with --profile
Attempts:
2 left
💡 Hint
Profiles control which services start by default.
🔀 Workflow
advanced
2:00remaining
Selective service start with multiple profiles
Given this docker-compose.yml snippet, which services will start when running docker-compose --profile frontend --profile debug up?
Docker
version: '3.9'
services:
  backend:
    image: backend:latest
  frontend:
    image: frontend:latest
    profiles:
      - frontend
  debug:
    image: debug:latest
    profiles:
      - debug
AOnly frontend service
BOnly frontend and debug services
Cbackend, frontend, and debug services
DOnly backend service
Attempts:
2 left
💡 Hint
Services without profiles always start unless profiles restrict them.
Best Practice
expert
2:00remaining
Best practice for using profiles in production
Which is the best practice when using Docker Compose profiles to manage selective services in a production environment?
AUse profiles to separate optional services like monitoring or debugging, enabling only needed profiles in production
BDefine all services without profiles and start only needed ones manually
CUse profiles to disable core services in production to save resources
DAvoid using profiles and rely on multiple compose files for service selection
Attempts:
2 left
💡 Hint
Profiles help manage optional services cleanly.