Suppose I have a Docker Compose file similar to this:
services:
serviceA:
image: imageA
serviceB:
image: imageB
serviceC:
image: imageC
profile:
- debug
serviceB-debug:
image: imageB
depends_on:
- serviceC
profile:
- debug
And the behavior I would like is:
- If I do not specify anything (e.g., when I run
docker compose up
), runserviceA
andserviceB
. - If I enable
debug
profile, runserviceA
,serviceC
and only once this is started,serviceB-debug
, which is the same asserviceB
but with the dependency I mention.
So, for all profiles I would like to run serviceA
(done); for debug
profile, serviceA
, serviceC
and serviceB-debug
(done); and for all profiles except debug
, serviceB
(the problem is here).
Is there a way to tell serviceB
to do not run when I select the debug
profile? Or, as alternative, is there a way to add that depends_on
condition to serviceB
only when I enable debug
profile?
I have searched in Compose documentation and different sites but I could not find anything for this use case.
1条答案
按热度按时间krcsximq1#
您可以将当前的docker-compose.yml拆分为docker-compose.yml和docker-compose.debug.yml,然后像以前一样运行基本设置:
和调试版本:
更多信息:docker-compose extends