Learn how to use profiles in Docker Compose


目录

With profiles you can define a set of active profiles so your Compose application model is adjusted for various usages and environments.

The services top-level element supports a profiles attribute to define a list of named profiles. Services without a profiles attribute are always enabled.

A service is ignored by Compose when none of the listed profiles match the active ones, unless the service is explicitly targeted by a command. In that case its profile is added to the set of active profiles.

All other top-level elements are not affected by profiles and are always active.

References to other services (by links, extends or shared resource syntax service:xxx) do not automatically enable a component that would otherwise have been ignored by active profiles. Instead Compose returns an error.

Illustrative example

services:
  web:
    image: web_image

  test_lib:
    image: test_lib_image
    profiles:
      - test

  coverage_lib:
    image: coverage_lib_image
    depends_on:
      - test_lib
    profiles:
      - test

  debug_lib:
    image: debug_lib_image
    depends_on:
      - test_lib
    profiles:
      - debug

In the above example:

Learn how to use profiles in Docker Compose.


版本号 #2
由 壳壳虫 创建于 2026-10-31 19:43:12 UTC
由 壳壳虫 更新于 2026-10-31 19:43:13 UTC