this post was submitted on 12 Oct 2023
18 points (95.0% liked)

Selfhosted

40006 readers
624 users here now

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:

  1. Be civil: we're here to support and learn from one another. Insults won't be tolerated. Flame wars are frowned upon.

  2. No spam posting.

  3. Posts have to be centered around self-hosting. There are other communities for discussing hardware or home computing. If it's not obvious why your post topic revolves around selfhosting, please include details to make it clear.

  4. Don't duplicate the full text of your blog or github here. Just post the link for folks to click.

  5. Submission headline should match the article title (don’t cherry-pick information from the title to fit your agenda).

  6. No trolling.

Resources:

Any issues on the community? Report it using the report flag.

Questions? DM the mods!

founded 1 year ago
MODERATORS
 

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

***
version: '3'
services:
  vpn:
   image: qmcgaw/gluetun:latest
   container_name: vpn
   restart: unless-stopped
   cap_add:
    - NET_ADMIN
   environment:
      - VPN_SERVICE_PROVIDER=custom
      - VPN_TYPE=wireguard
      - VPN_ENDPOINT_IP=####
      - VPN_ENDPOINT_PORT=####
      - WIREGUARD_PUBLIC_KEY=####
      - WIREGUARD_PRIVATE_KEY=####
      - WIREGUARD_PRESHARED_KEY=####
      - WIREGUARD_ADDRESSES=####
   devices:
    - /dev/net/tun:/dev/net/tun
   ports:
    - '8080:8080'
    #VPN
    - 8888:8888/tcp
    - 8388:8388/tcp
    - 8388:8388/udp
    - 8000:8000/tcp
    - 8584:8584
    - 8585:8585
   volumes:
    - /docker/appdata/gluetun:/gluetun
  sabnzbd:
    image: lscr.io/linuxserver/sabnzbd:latest
    container_name: sabnzbd
	network_mode: container:vpn
    volumes:
      - /docker/appdata/sabnzbd/data:/config
    restart: unless-stopped
  qbittorrent:  
    container_name: qbittorrent  
    image: linuxserver/qbittorrent:latest
    restart: unless-stopped
    network_mode: container:vpn  
    volumes:  
     - /docker/appdata/qbitorrent:/config  
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 1 points 1 year ago (1 children)

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.

[–] [email protected] 1 points 1 year ago* (last edited 1 year ago) (2 children)

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

…
ports: 
    - ‘8080:8080’
    - ‘9090:9090’ 
…

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

qtorrent:
    ports: 
        - 8080:8080

sabnzb:
    ports: 
        - 9090:8080

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

[–] [email protected] 1 points 1 year ago (1 children)

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

[–] [email protected] 1 points 1 year ago (1 children)

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

[–] [email protected] 1 points 1 year ago
[–] [email protected] 1 points 1 year ago

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