For local development I’m running a number of microservices using docker compose just as support for the service I’m currently working at, but most of the time I do not want to run all of them.
To achieve this I use profiles
in the service definition. Most of the services has a dependency on for example a database service. The problem is though that using profiles
is disables the possibility to use depends_on
, and instead the idea seems to be that profiles
should be shared by services that depend on each other, but that gives a symmetrical dependency unlike the asymmetrical dependency that depends_on
gives.
Simplified I have this:
services:
postgres:
profiles:
- postgres
- base
redis:
profiles:
- redis
- base
app1:
depends_on:
- postgres
profiles:
- app1
app2:
depends_on:
- postgres
- base
profiles:
- app2
Running just app1
results in this:
> docker compose --profile registry up
service "dreams-registry" depends on undefined service "postgres": invalid compose project
So how can I now start app2
and also have it automatically postgres
and redis
, but without starting app1 too?
I don’t really understand why profiles
should replace service names and depends_on
, seems like those things could coexist.