0
0
Dockerdevops~10 mins

Compose profiles for selective services in Docker - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Compose profiles for selective services
Define services in docker-compose.yml
Assign profiles to services
Run docker-compose with profiles
Only services in active profiles start
Other services remain stopped
This flow shows how services are defined with profiles and how running with specific profiles starts only those services.
Execution Sample
Docker
services:
  web:
    image: nginx
    profiles: ["frontend"]
  db:
    image: postgres
    profiles: ["backend"]
Defines two services with different profiles: 'web' in 'frontend' and 'db' in 'backend'.
Process Table
StepCommandActive ProfilesServices StartedServices Skipped
1docker-compose up --profile frontendfrontendwebdb
2docker-compose up --profile backendbackenddbweb
3docker-compose up --profile frontend --profile backendfrontend, backendweb, dbnone
4docker-compose upnone (default)none (services with profiles)web, db
💡 Execution stops after services start according to active profiles or default behavior.
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4
Active Profilesnonefrontendbackendfrontend, backendnone
Services Startednonewebdbweb, dbnone (no unprofiled services)
Key Moments - 2 Insights
Why does 'docker-compose up' without profiles start no services here?
Because both services have profiles assigned, and no default profile is active, so no service matches to start (see execution_table row 4).
Can multiple profiles be active at once?
Yes, as shown in execution_table row 3, running with multiple profiles starts all services assigned to any of those profiles.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, which services start when running 'docker-compose up --profile backend'?
Adb only
Bweb only
Cweb and db
Dnone
💡 Hint
Check execution_table row 2 under 'Services Started'
At which step do both 'web' and 'db' services start together?
AStep 1
BStep 2
CStep 3
DStep 4
💡 Hint
See execution_table row 3 for services started with multiple profiles
If the 'db' service had no profile, what would happen at step 4 when running 'docker-compose up'?
AOnly 'web' starts
B'db' starts, 'web' does not
CBoth 'web' and 'db' start
DNo services start
💡 Hint
Services without profiles start by default when no profile is specified (see explanation in key_moments)
Concept Snapshot
Compose profiles let you group services.
Assign profiles in docker-compose.yml under each service.
Run with --profile to start only those services.
Multiple profiles can be active together.
Services without profiles start only if no profile is specified.
Full Transcript
In Docker Compose, you can assign profiles to services to control which ones start. When you run 'docker-compose up' with a profile, only services in that profile start. If you run with multiple profiles, all services in those profiles start. Services without profiles start only if you run without any profile specified. This helps run selective services easily.