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"
    container_name: wireguard
      - NET_ADMIN
      - SYS_MODULE
      - pathToConfig:/config
      - pathToModules:/lib/modules
      - 8080:8080
      - net.ipv4.conf.all.src_valid_mark=1
      - net.ipv6.conf.all.disable_ipv6=0
    restart: unless-stopped
    network_mode: service:wireguard 
    container_name: qbittorrent
      - WEBUI_PORT=8080
      - pathToConfig:/config
      - pathToDownloads:/downloads
      - "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:

Wireguard creates an interface called wg0, with 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
1 Like