Bird
Raised Fist0
Dockerdevops~20 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What is the main purpose of using profiles in a Docker Compose file?
easy
A. To define environment variables for all services
B. To specify the Docker image version for services
C. To selectively start specific services based on the active profile
D. To set network configurations for containers

Solution

  1. Step 1: Understand the role of profiles in Docker Compose

    Profiles allow you to group services so you can start only those you want by activating a profile.
  2. Step 2: Compare with other options

    Environment variables, image versions, and network settings are configured differently, not via profiles.
  3. Final Answer:

    To selectively start specific services based on the active profile -> Option C
  4. Quick Check:

    Profiles control which services run [OK]
Hint: Profiles control service startup groups in Compose [OK]
Common Mistakes:
  • Confusing profiles with environment variables
  • Thinking profiles set image versions
  • Assuming profiles configure networks
2. Which of the following is the correct syntax to assign a service to a profile named debug in a Docker Compose file?
easy
A. profile: [debug]
B. profiles: [debug]
C. profiles: debug
D. profile: debug

Solution

  1. Step 1: Recall the correct key and format for profiles

    The key is profiles (plural) and it expects a list of profile names.
  2. Step 2: Validate the syntax

    Using YAML list syntax, profiles: [debug] is correct. Other options use singular or wrong types.
  3. Final Answer:

    profiles: [debug] -> Option B
  4. Quick Check:

    Profiles key is plural and uses list syntax [OK]
Hint: Use plural 'profiles' with a list for service assignment [OK]
Common Mistakes:
  • Using singular 'profile' instead of 'profiles'
  • Not using list syntax for profiles
  • Assigning profile as a string without brackets
3. Given this Compose snippet:
services:
  web:
    image: nginx
  debug:
    image: busybox
    profiles: [debug]
What happens when you run docker compose up without any profile?
medium
A. Only the web service starts
B. Both web and debug services start
C. Only the debug service starts
D. No services start

Solution

  1. Step 1: Identify which services have profiles

    The debug service is assigned to the profile 'debug', web has no profile.
  2. Step 2: Understand default behavior without profile

    Without specifying a profile, only services without profiles start.
  3. Final Answer:

    Only the web service starts -> Option A
  4. Quick Check:

    Services without profiles start by default [OK]
Hint: Without profile flag, only services without profiles run [OK]
Common Mistakes:
  • Assuming all services start by default
  • Thinking profile services start without activation
  • Confusing service names with profile names
4. You have this Compose file snippet:
services:
  app:
    image: myapp
    profiles: [prod]
  test:
    image: mytest
    profiles: [test]
You run docker compose --profile prod up but the app service does not start. What is the likely issue?
medium
A. The profile name is misspelled in the command
B. The app service must not have any profile to start
C. You must run docker compose up without profiles to start services
D. The Compose file syntax is invalid

Solution

  1. Step 1: Check profile names in Compose and command

    The service uses profile 'prod'. If the command misspells it, the service won't start.
  2. Step 2: Understand profile activation

    Only services matching the activated profile start. If the profile name is wrong, no matching service starts.
  3. Final Answer:

    The profile name is misspelled in the command -> Option A
  4. Quick Check:

    Profile names must match exactly [OK]
Hint: Check exact profile spelling in command and Compose file [OK]
Common Mistakes:
  • Assuming services without profiles start with any profile
  • Thinking Compose file syntax error causes this
  • Believing profiles are optional for service start
5. You want to start only the db and cache services using profiles. Your Compose file has:
services:
  db:
    image: postgres
    profiles: [backend]
  cache:
    image: redis
    profiles: [backend]
  frontend:
    image: nginx
    profiles: [frontend]
Which command will start only the db and cache services?
hard
A. docker compose up
B. docker compose --profile frontend up
C. docker compose --profile db cache up
D. docker compose --profile backend up

Solution

  1. Step 1: Identify profiles assigned to db and cache

    Both db and cache are under the 'backend' profile.
  2. Step 2: Use the correct command to activate the backend profile

    Running docker compose --profile backend up starts only services in 'backend'.
  3. Final Answer:

    docker compose --profile backend up -> Option D
  4. Quick Check:

    Activate profile matching services to start them [OK]
Hint: Use --profile with the shared profile name to start grouped services [OK]
Common Mistakes:
  • Using profile name not assigned to services
  • Running without profile starts no profile services only
  • Trying to list services in command instead of profile
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard