简体   繁体   中英

Is there a way to exclude a service from being executed with one specific profile in Docker Compose?

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 (eg, 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.

You can split current docker-compose.yml to docker-compose.yml and docker-compose.debug.yml and then run basic setup as before:

docker-compose up -d

And debug version with:

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

More info: docker-compose extends

For profiles, you would need to add some "other" profile and mark serviceB (non-debug) with that. docker-compose profiles do not seem to have an option to disable service in profile (something like ".debug").

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM