posted in Selfhosted

Question about using gluetun for other containers

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?

Replying to @⁨chagall@lemmy.world⁩

I have several dependencies in my arr stack. Gluetun depends on privateer and qbittorrent depends on gluetun being healthy

Here’s part of my compose file. I hope this helps.

############################

GLUETUN

############################

gluetun: image: qmcgaw/gluetun:latest container_name: gluetun hostname: gluetun

depends_on:
  privateerr:
    condition: service_healthy

restart: unless-stopped

cap_add:
  - NET_ADMIN

devices:
  - /dev/net/tun:/dev/net/tun

entrypoint:
  - /bin/sh
  - /privateerr/gluetun-entrypoint-wrapper.sh

volumes:
  - /srv/docker/gluetun:/gluetun:rw
  - /srv/docker/gluetun:/tmp/gluetun:rw
  - /srv/docker/gluetun/scripts:/privateerr:ro

environment:
  - VPN_SERVICE_PROVIDER=custom
  - VPN_TYPE=wireguard
   
  # credentials removed 
  
  - PRIVATEERR_METADATA_PATH=/gluetun/wireguard/privateerr.env
  - PRIVATEERR_GLUETUN_METADATA_WAIT_SECONDS=120

  - GLUETUN_DEFAULT_ENTRYPOINT=/gluetun-entrypoint

  - HEALTH_SERVER_ADDRESS=127.0.0.1:9999
  - HEALTH_RESTART_VPN=on

# Only ports for containers that actually share gluetun's network
# namespace are published here: flaresolverr + both qbittorrents.
# (The arrs moved to the arrnet network and publish their own ports.)
ports:
  - 8080:8080 #qbittorrent
  - 8081:8081 #qbittorrent_other
  - 8191:8191 #flaresolverr
  - 6881:6881 #qbittorrent
  - 6881:6881/udp #qbittorrent
  - 6882:6882 #qbittorrent_other
  - 6882:6882/udp #qbittorrent_other


healthcheck:
  test: ["CMD-SHELL", "wget -q -O /dev/null http://127.0.0.1:9999/ || exit 1"]
  interval: 30s
  timeout: 10s
  retries: 3

############################

QBITTORRENT

############################

STAYS ON THE VPN – this is the whole point of the gluetun network.

qbittorrent: image: lscr.io/linuxserver/qbittorrent:latest container_name: qbittorrent network_mode: “service:gluetun” depends_on:
# Wait for the gluetun container to be ‘healthy’ (VPN connected) gluetun: condition: service_healthy___

Edited ⁨⁨Nov⁩ ⁨10⁩, ⁨2026⁩, ⁨21:38⁩⁩en