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  
  • webnet@lemmy.world
    link
    fedilink
    English
    arrow-up
    6
    ·
    1 year ago

    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. https://registry.hub.docker.com/r/linuxserver/qbittorrent

      qbittorrent:  
        container_name: qbittorrent  
        image: linuxserver/qbittorrent:latest
        environment:
          - WEBUI_PORT=8585
        restart: unless-stopped
        network_mode: container:vpn  
        volumes:  
         - /docker/appdata/qbitorrent:/config  
    
    • Fjor@lemm.eeOP
      link
      fedilink
      English
      arrow-up
      4
      ·
      1 year ago

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

  • Appoxo@lemmy.dbzer0.com
    link
    fedilink
    English
    arrow-up
    1
    ·
    edit-2
    1 year ago

    You could join two different networks

    And bind the port to that.

    Example:

        ports: 
           - 8880:8880 #HTTP port #optional 
           - 8443:8443 #HTTPS port 
           - 3478:3478/udp 
           - 10001:10001/udp 
           - 8080:8080 
           - "10.0.0.253:1900:1900/udp" #optional 
           - 8843:8843 #optional 
           - 6789:6789 #optional 
           - 5514:5514/udp #optional 
         networks: 
           service: 
           net: 
             ipv4_address: 10.0.0.253
    

    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.

  • thepianistfroggollum@lemmynsfw.com
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    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@lemmy.world
      link
      fedilink
      English
      arrow-up
      4
      ·
      1 year ago

      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

    • Fjor@lemm.eeOP
      link
      fedilink
      English
      arrow-up
      1
      ·
      edit-2
      1 year ago

      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
      • thepianistfroggollum@lemmynsfw.com
        link
        fedilink
        English
        arrow-up
        1
        ·
        1 year ago

        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.

      • breadsmasher@lemmy.world
        link
        fedilink
        English
        arrow-up
        1
        ·
        edit-2
        1 year ago

        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@lemm.eeOP
          link
          fedilink
          English
          arrow-up
          1
          ·
          1 year ago

          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@lemmy.world
            link
            fedilink
            English
            arrow-up
            1
            ·
            edit-2
            1 year ago

            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

            • Fjor@lemm.eeOP
              link
              fedilink
              English
              arrow-up
              1
              ·
              1 year ago

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

            • Fjor@lemm.eeOP
              link
              fedilink
              English
              arrow-up
              1
              ·
              1 year ago

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