I use gluetun, my arr stack and bittorrent client in a single docker-compose. I use the syntax

    depends_on:
      gluetun:
        condition: service_healthy

in the stack to make sure that the bittorrent client doesn’t try to connect too early. All that works great.

I also use that same VPN connection for other containers too (not in the same docker-compose stack). I do that by simply using network_mode: "container:gluetun" in the second yaml file. But I’d like to use the same depends_on syntax. But it errors out because gluetun is undefined in the second stack.

So my question is, how do I make sure the containers in docker compose stack 2 start after docker compose stack 1 (the one with gluetun) is healthy?

  • Azura The Spellkissed@lemmy.blahaj.zone
    link
    fedilink
    English
    arrow-up
    2
    ·
    12 days ago

    Afaik you don’t need the depends_on at all, it’s basically implied. If you configure the container to use gluetun’s network, it shouldn’t just bypass it even if there’s any problem with the gluetun container. The gluetun documentation also says to just use network_mode: container:gluetun, even when connecting from a divergent compose.yaml. if you want to be sure, maybe test out what happens if that gluetun is down.

    • Sockenklaus@sh.itjust.works
      link
      fedilink
      English
      arrow-up
      1
      ·
      11 days ago

      This needs to be top comment, because it’s the correct answer: You don’t need depends_on! Just use network_mode: container:gluetun.

  • ohulancutash@feddit.uk
    link
    fedilink
    English
    arrow-up
    1
    ·
    edit-2
    11 days ago

    You can refer to a service in another docker compose file using the extends directive but this can’t influence startup order.

  • xmrlist@lemmy.world
    link
    fedilink
    English
    arrow-up
    1
    ·
    11 days ago

    One option nobody mentioned: Compose has a top-level include: (Compose v2.20+). In stack 2 add

    include:
      - ../stack1/docker-compose.yml
    

    and gluetun becomes part of the same project, so depends_on: gluetun: condition: service_healthy works again. The catch is that docker compose up/down in stack 2 now manages gluetun too, so it’s best if stack 1 is only gluetun and everything else lives in its own files.