A Compose profile is a way to group services in a Docker Compose file so you can selectively start those services by enabling specific profiles (services without profiles always start too).
Click to reveal answer
beginner
How do you define a profile for a service in a Docker Compose file?
You add a 'profiles' key under the service with a list of profile names. For example:
services:
web:
image: nginx
profiles:
- frontend
Click to reveal answer
beginner
How do you start Docker Compose with a specific profile?
Use the command: docker compose --profile <profile_name> up to start services in that profile (in addition to services without profiles).
Click to reveal answer
intermediate
What happens if you run 'docker compose up' without specifying any profile?
Docker Compose starts all services that have no profile specified. Services assigned to profiles are not started unless their profile is enabled.
Click to reveal answer
beginner
Why use Compose profiles for selective services?
Profiles help you manage complex projects by starting only the services you need for a specific task, like development, testing, or production, saving resources and time.
Click to reveal answer
How do you specify a profile for a service in a Docker Compose file?
AAdd a 'profiles' key with a list of profile names under the service
BUse 'profile:' with a single profile name under the service
CAdd 'profile' as an environment variable
DProfiles are set only via command line, not in the file
✗ Incorrect
The correct way is to add a 'profiles' key with a list of profile names under the service.
What command starts services in the 'frontend' profile only?
Adocker compose up frontend
Bdocker compose --profile frontend up
Cdocker compose start frontend
Ddocker compose run frontend
✗ Incorrect
Use 'docker compose --profile frontend up' to start services in the 'frontend' profile (in addition to services without profiles).
If a service has no profile defined, when does it start?
AAlways, regardless of profiles specified
BOnly with the 'default' profile explicitly enabled
CNever, it must have a profile
DOnly when a profile is specified
✗ Incorrect
Services without profiles always start when you run 'docker compose up', regardless of profiles specified.
Why might you use profiles in Docker Compose?
ATo set network configurations
BTo define environment variables
CTo group services for selective startup
DTo build images automatically
✗ Incorrect
Profiles group services so you can start only the ones you want.
What happens if you run 'docker compose up' with no profiles specified?
ANo services start
BAll services start regardless of profiles
COnly services with profiles start
DOnly services without profiles start
✗ Incorrect
Only services without profiles start by default when no profile is specified.
Explain how to use Compose profiles to start only selected services in a Docker Compose project.
Think about grouping services and using command line to select them.
You got /4 concepts.
Describe the benefits of using Compose profiles in managing Docker services.
Consider how profiles help organize and control service execution.
You got /4 concepts.
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
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.
Step 2: Compare with other options
Environment variables, image versions, and network settings are configured differently, not via profiles.
Final Answer:
To selectively start specific services based on the active profile -> Option C
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
Step 1: Recall the correct key and format for profiles
The key is profiles (plural) and it expects a list of profile names.
Step 2: Validate the syntax
Using YAML list syntax, profiles: [debug] is correct. Other options use singular or wrong types.
Final Answer:
profiles: [debug] -> Option B
Quick Check:
Profiles key is plural and uses list syntax [OK]
Hint: Use plural 'profiles' with a list for service assignment [OK]