是否有办法在Docker Compose中使用一个特定配置文件来排除正在执行的服务?

4urapxun  于 2022-12-03  发布在  Docker
关注(0)|答案(1)|浏览(173)

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 ), run serviceA and serviceB .
  • If I enable debug profile, run serviceA , serviceC and only once this is started, serviceB-debug , which is the same as serviceB 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.

krcsximq

krcsximq1#

您可以将当前的docker-compose.yml拆分为docker-compose.yml和docker-compose.debug.yml,然后像以前一样运行基本设置:

docker-compose up -d

和调试版本:

docker-compose -f docker-compose.yml -f docker-compose.debug.yml up -d

更多信息:docker-compose extends

相关问题