Connecting to a container using network_mode service from another computer

Hello intellectuals!

I have the following docker-compose (some parts removed in an attempt to keep it brief):

version: "2.1"
services:
  wireguard:
    image: lscr.io/linuxserver/wireguard
    container_name: wireguard
    cap_add:
      - NET_ADMIN
      - SYS_MODULE
    volumes:
      - pathToConfig:/config
      - pathToModules:/lib/modules
    ports:
      - 8080:8080
    sysctls:
      - net.ipv4.conf.all.src_valid_mark=1
      - net.ipv6.conf.all.disable_ipv6=0
    restart: unless-stopped
  qbittorrent:
    image: lscr.io/linuxserver/qbittorrent
    network_mode: service:wireguard 
    container_name: qbittorrent
    environment:
      - WEBUI_PORT=8080
    volumes:
      - pathToConfig:/config
      - pathToDownloads:/downloads
    depends_on:
      - "wireguard"
    restart: unless-stopped

On my server everything seems to work fine, and I’m able to reach the qbittorrent web gui from localhost. The problem I’m having is that the connection times out when trying to connect to the qbittorrent web gui from another computer on my network (i.e. 192.x.x.x:8080).

This is probably obvious but I’m a complete beginner, and I can’t even tell if this sort of thing is supposed to work “out of the box”, or if there is something elementary I’m missing. I’ve searched around for answers but to be truthful I don’t understand most of them.

So my question is, how do I go about connecting to the qbittorrent web gui from another computer on my network?

Maybe I should also mention that I’m running Ubuntu desktop 20.4 LTS.

shalashaska02 provided a solution on reddit: Reddit - Dive into anything.

Wireguard creates an interface called wg0, with 10.13.13.1 ip, or something like that. If you want to access it from outside, then you must forward packets that come on port 8080 to wg0 interface on port 8080, and you can use iptables to achieve that.

Add this command on the computer with qbittorent installed:

sudo iptables -t nat -I PREROUTING -p tcp --dport 8080 -j DNAT --to-destination 10.13.13.1:8080
1 Like