Exclude services from being started with docker-compose using profiles?

My docker-compose.yml defines multiple services which represent the full application stack. In development mode, I’d like to dynamically exclude certain services, so that I can run them from an IDE.

As of Docker Compose 1.28 it is possible to assign profiles to services as documented here but as far as I have understood, it only allows specifying which services shall be started, not which ones shall not get started.

In the end I’d like to achieve something like this (pseduo command):

docker-compose up --exclude service1,service2

Do you have any recommendations on how to exclude certain services? Would that be possible using Docker Compose profiles?

What you can do is instead of exclude services you can simply include all services that you want to start up.

Following the docker compose up --help documentation you can pass mutiple service names.
To make sure linked containers (when using depends_on attribute) are not started you should add the --no-deps flag.

Your command should look like this:
docker compose up --no-deps service1, service2, service5

I can start one service, but I cannot start multiple services.

docker compose up --no-deps service1 // ok

docker compose up --no-deps service1, service2, service5 // not ok

I had to do this:

docker-compose up --no-deps service1 service2 // omit the comma
docker-compose up service1 service2 // omit comma and don’t need “–no-deps” also works