Can you define optional docker-compose services?

Docker compose now supports profiles, which allow you to a) disable one or more services by default, and b) enable them when docker compose is ran with the corresponding --profile argument.

This is done by adding a profiles key to your service in the docker-compose.yml file. Services that have don’t have this key are always started by docker-compose (for all profiles).

For example, with the following docker-compose.yml file

version: '3.9'
services
  app_service:
    # ...
  test_service:
    profiles:
      - testing
    # ...

Running docker-compose up will only start the app_service, and running docker-compose --profile testing up will start both the app_service and the test_service.

Multiple profiles can be specified by passing multiple --profile flags.

More info can be found here: https://docs.docker.com/compose/profiles/

Edit: I had to update to docker engine v20.10.5 for this to work.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)