Search or ask Docker

Profiles

Learn about the profiles attribute

View Markdown

Profiles let you run only the parts of your Compose application that you need for a given environment or task, such as development, testing, or debugging.

To use profiles, add a profiles attribute to a service or job. It takes a list of profile names:

  • No profiles attribute: The service or job is always enabled.
  • With profiles: The service or job is enabled only when at least one of its profiles is active.

Compose ignores a service or job whose profiles are all inactive. The exception is when you name it in a command, for example docker compose run <name>.

Profiles only affect services and jobs. All other top-level elements, such as networks, volumes, configs, and secrets, are always active.

Note

A service can only reference another service in an active profile. References made with links, depends_on, or service:<name> don't activate the profile of the service they point to, and Compose returns an error if that profile is inactive. A depends_on entry with required: false is ignored instead. With extends, the extending service inherits the profiles of the service it extends, so it is inactive when none of them is active.

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:

  • If the Compose application model is parsed when no profile is enabled, it only contains the web service.
  • If the profile test is enabled, the model contains the services test_lib and coverage_lib, and service web, which is always enabled.
  • If the profile debug is enabled, the model contains both web and debug_lib services, but not test_lib and coverage_lib, and as such the model is invalid regarding the depends_on constraint of debug_lib.
  • If the profiles debug and test are enabled, the model contains all services; web, test_lib, coverage_lib and debug_lib.
  • If Compose is executed with test_lib as the explicit service to run, test_lib and the test profile are active even if test profile is not enabled.
  • If Compose is executed with coverage_lib as the explicit service to run, the service coverage_lib and the profile test are active and test_lib is pulled in by the depends_on constraint.
  • If Compose is executed with debug_lib as the explicit service to run, again the model is invalid regarding the depends_on constraint of debug_lib, since debug_lib and test_lib have no common profiles listed.
  • If Compose is executed with debug_lib as the explicit service to run and profile test is enabled, profile debug is automatically enabled and service test_lib is pulled in as a dependency starting both services debug_lib and test_lib.

Learn how to use profiles in Docker Compose.