✦ For everyone, free.

Practical knowledge for real and everyday life

Home

9.3.5.1 Optional Compose Services

A focused guide to Optional Compose Services, connecting core concepts with practical Docker and container operations.

Optional Compose services are services tagged with a profile, meaning they're defined within the Compose file but excluded from a default docker compose up unless their specific profile is explicitly activated, supporting situational needs without affecting everyday usage.

Defining a Service as Optional

Tagging a service with a profile makes its inclusion conditional, rather than automatic.

services:
  api:
    build: .
  load-test:
    image: load-testing-tool:1.0
    profiles:
      - testing

A default docker compose up -d starts only api; load-test remains excluded unless its profile is explicitly activated.

Common Categories of Optional Services

Debugging utilities, data seeding scripts, load testing tools, and administrative interfaces are all natural candidates for being defined as optional, since they're useful in specific situations but unnecessary for everyday operation.

services:
  admin-panel:
    image: admin-ui:1.0
    profiles:
      - admin
  seed-db:
    build: .
    command: npm run seed
    profiles:
      - seeding
Activating an Optional Service When Actually Needed

A specific optional service becomes available simply by activating its associated profile at startup.

docker compose --profile seeding up -d seed-db
Why Optional Services Keep a Compose File Comprehensive Without Adding Friction

Consolidating every service an application might need — including occasional, situational ones — into a single Compose file, using profiles to keep the optional ones out of the way by default, avoids both maintaining separate files for these scenarios and unnecessarily running services that aren't needed most of the time.

docker compose up -d
Why Optional Compose Services Matter

The ability to define services that exist within the Compose file but stay dormant unless specifically needed is a valuable way to keep a single, comprehensive Compose file practical for everyday use while still supporting the full range of situational needs a project might have.