'docker compose with profiles

I fail to understand how profiles work in docker compose.

So, I'm having two services defined in the docker-compose.yml

services:
  db:
    (...)
    profiles:
      - default
      - db
  app:
    (...)
    profiles:
      - default

When I run docker compose --profile db it indicates correctly to run only the db service [Running 1/0]. However, the app is also "attached".

docker compose with profiles

How can I prevent the app being attached?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source