>_ IzzyLab

Hands-on task

This task is step 16 of the course “CI/CD: pipelines and docker compose”

docker-compose: profiles

medium~10 min

In /root/docker-compose.yml, define a service web (nginx, always active), debug (busybox, profile debug), and metrics (profile monitoring). Services with a profile come up only when the profile is explicitly requested. The file must conform to the Compose Specification schema — run yamlschema compose /root/docker-compose.yml to see the errors.

What you'll practise:
  • docker compose
  • profiles
  • yaml
  • conditional service startup

Topic breakdown

Profiles in Compose are a way to keep in one docker-compose.yml services that aren't needed in the normal mode (debugging, metrics, one-off jobs). A service with a profiles key comes up only when the corresponding profile is requested explicitly (via a flag or an environment variable), while a service without that key is always active. A single service can belong to several profiles — then any one of them activates it.

What's checked

  1. the file passes the Compose schema
  2. debug has the debug profile
  3. metrics in the monitoring profile, web always active

What it looks like