There have been multiple accounts created with the sole purpose of posting advertisement posts or replies containing unsolicited advertising.

Accounts which solely post advertisements, or persistently post them may be terminated.

How to specify port number in compose file that is behind vpn container

Hi there!

I’m trying to set up two services (through docker) both of which use port 8080 by default. However I am wanting these to services to sit behind a VPN using Gluetun. I added both of the ports I want to use to the compose file, but this just leads to only one of the services working as the other one will say “port already in use”. How can I strictly tell these services what port they shall use in the compose file?

This is how I did it so far;

docker-compose.yml


<span style="color:#323232;">---
</span><span style="color:#63a35c;">version</span><span style="color:#323232;">: </span><span style="color:#183691;">'3'
</span><span style="color:#63a35c;">services</span><span style="color:#323232;">:
</span><span style="color:#323232;">  </span><span style="color:#63a35c;">vpn</span><span style="color:#323232;">:
</span><span style="color:#323232;">   </span><span style="color:#63a35c;">image</span><span style="color:#323232;">: </span><span style="color:#183691;">qmcgaw/gluetun:latest
</span><span style="color:#323232;">   </span><span style="color:#63a35c;">container_name</span><span style="color:#323232;">: </span><span style="color:#183691;">vpn
</span><span style="color:#323232;">   </span><span style="color:#63a35c;">restart</span><span style="color:#323232;">: </span><span style="color:#183691;">unless-stopped
</span><span style="color:#323232;">   </span><span style="color:#63a35c;">cap_add</span><span style="color:#323232;">:
</span><span style="color:#323232;">    - </span><span style="color:#183691;">NET_ADMIN
</span><span style="color:#323232;">   </span><span style="color:#63a35c;">environment</span><span style="color:#323232;">:
</span><span style="color:#323232;">      - </span><span style="color:#183691;">VPN_SERVICE_PROVIDER=custom
</span><span style="color:#323232;">      - </span><span style="color:#183691;">VPN_TYPE=wireguard
</span><span style="color:#323232;">      - </span><span style="color:#183691;">VPN_ENDPOINT_IP=####
</span><span style="color:#323232;">      - </span><span style="color:#183691;">VPN_ENDPOINT_PORT=####
</span><span style="color:#323232;">      - </span><span style="color:#183691;">WIREGUARD_PUBLIC_KEY=####
</span><span style="color:#323232;">      - </span><span style="color:#183691;">WIREGUARD_PRIVATE_KEY=####
</span><span style="color:#323232;">      - </span><span style="color:#183691;">WIREGUARD_PRESHARED_KEY=####
</span><span style="color:#323232;">      - </span><span style="color:#183691;">WIREGUARD_ADDRESSES=####
</span><span style="color:#323232;">   </span><span style="color:#63a35c;">devices</span><span style="color:#323232;">:
</span><span style="color:#323232;">    - </span><span style="color:#183691;">/dev/net/tun:/dev/net/tun
</span><span style="color:#323232;">   </span><span style="color:#63a35c;">ports</span><span style="color:#323232;">:
</span><span style="color:#323232;">    - </span><span style="color:#183691;">'8080:8080'
</span><span style="color:#323232;">    </span><span style="font-style:italic;color:#969896;">#VPN
</span><span style="color:#323232;">    - </span><span style="color:#183691;">8888:8888/tcp
</span><span style="color:#323232;">    - </span><span style="color:#183691;">8388:8388/tcp
</span><span style="color:#323232;">    - </span><span style="color:#183691;">8388:8388/udp
</span><span style="color:#323232;">    - </span><span style="color:#183691;">8000:8000/tcp
</span><span style="color:#323232;">    - </span><span style="color:#183691;">8584:8584
</span><span style="color:#323232;">    - </span><span style="color:#183691;">8585:8585
</span><span style="color:#323232;">   </span><span style="color:#63a35c;">volumes</span><span style="color:#323232;">:
</span><span style="color:#323232;">    - </span><span style="color:#183691;">/docker/appdata/gluetun:/gluetun
</span><span style="color:#323232;">  </span><span style="color:#63a35c;">sabnzbd</span><span style="color:#323232;">:
</span><span style="color:#323232;">    </span><span style="color:#63a35c;">image</span><span style="color:#323232;">: </span><span style="color:#183691;">lscr.io/linuxserver/sabnzbd:latest
</span><span style="color:#323232;">    </span><span style="color:#63a35c;">container_name</span><span style="color:#323232;">: </span><span style="color:#183691;">sabnzbd
</span><span style="color:#323232;">	</span><span style="color:#63a35c;">network_mode</span><span style="color:#323232;">: </span><span style="color:#183691;">container:vpn
</span><span style="color:#323232;">    </span><span style="color:#63a35c;">volumes</span><span style="color:#323232;">:
</span><span style="color:#323232;">      - </span><span style="color:#183691;">/docker/appdata/sabnzbd/data:/config
</span><span style="color:#323232;">    </span><span style="color:#63a35c;">restart</span><span style="color:#323232;">: </span><span style="color:#183691;">unless-stopped
</span><span style="color:#323232;">  </span><span style="color:#63a35c;">qbittorrent</span><span style="color:#323232;">:  
</span><span style="color:#323232;">    </span><span style="color:#63a35c;">container_name</span><span style="color:#323232;">: </span><span style="color:#183691;">qbittorrent  
</span><span style="color:#323232;">    </span><span style="color:#63a35c;">image</span><span style="color:#323232;">: </span><span style="color:#183691;">linuxserver/qbittorrent:latest
</span><span style="color:#323232;">    </span><span style="color:#63a35c;">restart</span><span style="color:#323232;">: </span><span style="color:#183691;">unless-stopped
</span><span style="color:#323232;">    </span><span style="color:#63a35c;">network_mode</span><span style="color:#323232;">: </span><span style="color:#183691;">container:vpn  
</span><span style="color:#323232;">    </span><span style="color:#63a35c;">volumes</span><span style="color:#323232;">:  
</span><span style="color:#323232;">     - </span><span style="color:#183691;">/docker/appdata/qbitorrent:/config  
</span>
Decronym Bot , (edited )

Acronyms, initialisms, abbreviations, contractions, and other phrases which expand to something larger, that I’ve seen in this thread:

Fewer Letters More Letters
HTTP Hypertext Transfer Protocol, the Web
HTTPS HTTP over SSL
IP Internet Protocol
SSL Secure Sockets Layer, for transparent encryption
VPN Virtual Private Network

4 acronyms in this thread; the most compressed thread commented on today has 10 acronyms.

[Thread for this sub, first seen 12th Oct 2023, 16:55] [FAQ] [Full list] [Contact] [Source code]

Appoxo ,
@Appoxo@lemmy.dbzer0.com avatar

You could join two different networks

And bind the port to that.

Example:


<span style="color:#323232;">    ports: 
</span><span style="color:#323232;">       - 8880:8880 #HTTP port #optional 
</span><span style="color:#323232;">       - 8443:8443 #HTTPS port 
</span><span style="color:#323232;">       - 3478:3478/udp 
</span><span style="color:#323232;">       - 10001:10001/udp 
</span><span style="color:#323232;">       - 8080:8080 
</span><span style="color:#323232;">       - "10.0.0.253:1900:1900/udp" #optional 
</span><span style="color:#323232;">       - 8843:8843 #optional 
</span><span style="color:#323232;">       - 6789:6789 #optional 
</span><span style="color:#323232;">       - 5514:5514/udp #optional 
</span><span style="color:#323232;">     networks: 
</span><span style="color:#323232;">       service: 
</span><span style="color:#323232;">       net: 
</span><span style="color:#323232;">         ipv4_address: 10.0.0.253
</span>

In that case I binded the container to the service network but needed a static IP reachable by outside devices.
So I created a macvlan adapter, binded the port 1900 to that adress and all was fine.
Should probably work for your use case.

webnet ,

qBittorrent has an option to define the WEBUI_PORT. If you want to access it on say, port 8585, set this environment variable to WEBUI_PORT=8585. Then in gluetun, continue to reference it as you do above. Hope this helps. registry.hub.docker.com/r/…/qbittorrent


<span style="color:#323232;">  qbittorrent:  
</span><span style="color:#323232;">    container_name: qbittorrent  
</span><span style="color:#323232;">    image: linuxserver/qbittorrent:latest
</span><span style="color:#323232;">    environment:
</span><span style="color:#323232;">      - WEBUI_PORT=8585
</span><span style="color:#323232;">    restart: unless-stopped
</span><span style="color:#323232;">    network_mode: container:vpn  
</span><span style="color:#323232;">    volumes:  
</span><span style="color:#323232;">     - /docker/appdata/qbitorrent:/config  
</span>
Fjor OP ,

Ah thanks! That solves one of the services at least. Merciii <3

SheeEttin ,

docs.docker.com/compose/…/compose-file-v3/

thepianistfroggollum ,

Just use a different port number. I’m not sure why it’s necessary to use the same one since you can change qbittorrent’s port in the config files.

breadsmasher ,
@breadsmasher@lemmy.world avatar

You can also map different ports to the container. For sake of argument lets say qtorrent had a fixed port you cannot change, that’s just what the application listens to. You can then map a different container port to that application port.

tldr, OP, you can’t have two containers in docker on the same container port

thepianistfroggollum ,

Fair enough, but OPs problem can be solved by changing a 0 to a 1 in a single file.

Fjor OP ,

how haha

Fjor OP ,

Right, my bad for the misleading/wrong title. This is my question - how do i map a port to a container that uses network_mode: …

Fjor OP ,

Sorry that was my question, dont want to use the port twice, I want to tell the compose file what to use for each container, but I dont know how.

  • Fixed the title, mb
breadsmasher ,
@breadsmasher@lemmy.world avatar

In the VPN service you just expose the port you want and map it to the listener port on the service

vpn: ports: - 5000:8080 - 6000:8080

where you have

servicea listening on 8080 and serviceB on 8080 but exposed on 5000 and 6000 in the VPN service

for example

Fjor OP ,

sorry im still quite new to this… do u have an example of another compose file that does this? Not sure where I put what.

breadsmasher ,
@breadsmasher@lemmy.world avatar

On my phone so I haven’t got the access to give you a good example.

You see in your compose file in your original post you have ‘8080:8080’ under ports?

You should be able to add another line, the left hand side of the colon exposing a different port like so


<span style="color:#323232;">…
</span><span style="color:#323232;">ports: 
</span><span style="color:#323232;">    - ‘8080:8080’
</span><span style="color:#323232;">    - ‘9090:9090’ 
</span><span style="color:#323232;">…
</span>

then one service you can access on port 8080 and the other you access on 9090

then under each service you want to expose you add the other port mappings


<span style="color:#323232;">qtorrent:
</span><span style="color:#323232;">    ports: 
</span><span style="color:#323232;">        - 8080:8080
</span><span style="color:#323232;">
</span><span style="color:#323232;">sabnzb:
</span><span style="color:#323232;">    ports: 
</span><span style="color:#323232;">        - 9090:8080
</span>

edit - so you should end up with the vpn container exposing 8080 which points to the service exposing 8080 which maps to application listening on 8080

and the same for 9090 -> 9090 -> 8080

Fjor OP ,

but I thought the containers had to have “network_mode: container:vpn”, in order to strictly only be able to communicate through the VPN.

breadsmasher ,
@breadsmasher@lemmy.world avatar

When I am home Ill get an example from my setup 👍

Fjor OP ,

mercii :)

Fjor OP ,

when I do this I get the error message that the ports are already in use by the vpn container :|

thepianistfroggollum ,

Ah, well the qbittorrent config file should live in the directory you mapped to /config. I think you can pull the default one and edit it for your container.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • [email protected]
  • random
  • lifeLocal
  • goranko
  • All magazines