Try network_mode: service:gluetun
It uses the container name instead of the Id number
A place to share alternatives to popular online services that can be self-hosted without giving up privacy or locking you into a service you don't control.
Rules:
Be civil.
No spam.
Posts are to be related to self-hosting.
Don't duplicate the full text of your blog or readme if you're providing a link.
Submission headline should match the article title.
No trolling.
Promotion posts require active participation, with an account that is at least 30 days old. F/LOSS without a paywall has exceptions, with requirements. See the rules link for details. Tags [CBH] or [AIP] are required, see the links in Rule 8 for details.
AI-related discussions and AI-involved promotional posts have additional requirements for tagging, as noted in Rule 7 and the AI & Promotional Post Expanded Rules post, and find example disclosures here.
Resources:
Any issues on the community? Report it using the report flag.
Questions? DM the mods!
Try network_mode: service:gluetun
It uses the container name instead of the Id number
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.
You can't use dependencies cross-stack.
If you know the IP that the gluetun interface is supposed to have you tell the BT client to use that interface as output interface. Usually BT clients have this option, other apps might not.
Another thing you can do is wrap the client in a script that waits for the interface to be up (respond to ping) before it moves one. Something like (in sh):
while ! ping -c 1 -q -W 1 "$IP" &>/dev/null ; do
echo "Waiting for ${IP} to come up..."
sleep 5
done
# run BT client here
Alternatively if the gluetun interface itself doesn't respond to ping, you can ping something else (like 1.1.1.1) through the interface, and use the -I ${IP} option for ping to bind to it for output.
Yeah, depends_on only works inside a single compose file/project, so it can't see gluetun from stack 2 — that's why you're getting the undefined error. There's no built-in cross-stack depends_on, unfortunately.
The cleanest fix IMO is to merge them into one compose file if you can, then depends_on with service_healthy works for everything. If you really want to keep them seperate, a couple of options:
One caveat too: service_healthy only means the container is healthy, not neccessarily that the VPN tunnel itself is fully up, so it's still worth checking the torrent client actually has the VPN IP before you trust it. FYI, you can test that from inside the client container with curl to an IP checker.
Darn. I had the same question as OP but have been working around it by combining everything into the same stack. It's just a bit of a pain to edit the stack every time I want to test something or retire a service.
Good work-arounds though! Maybe I should move to a script-based startup... Only trouble is all my containers are tagged with restart: unless-stopped so Docker restarts all of it at once on reboot which would mess up the order. Hmm.