qdm12 / gluetun

VPN client in a thin Docker container for multiple VPN providers, written in Go, and using OpenVPN or Wireguard, DNS over TLS, with a few proxy servers built-in.
https://hub.docker.com/r/qmcgaw/gluetun
MIT License
8.04k stars 372 forks source link

Help: Conflicting ports on images (How to remap ports?) #343

Closed lx30011 closed 3 years ago

lx30011 commented 3 years ago

Host OS (approximate answer is fine too): Ubuntu 20.04.1 LTS

Is this urgent?: No

What VPN provider are you using: Private Internet Access

What is the version of the program

Running version latest built on 2021-01-04T13:46:01Z (commit bf6bab7)

What's the problem 🤔

I'm trying to route jlesage/firefox as well as jlesage/jdownloader-2 through the gluetun service, but both images use port 5800 by default and as far as I can tell, the images provide no option to change the port through e. g. environment variables. Normally, I would just remap the ports in the respective ports sections in the docker compose file, but I don't know how to this with gluetun.

What are you using to run your container?: Docker Compose

Please also share your configuration file:

version: '3.9'

services:
  gluetun:
    container_name: gluetun
    image: qmcgaw/gluetun
    cap_add:
      - NET_ADMIN
    environment:
      - VPNSP=private internet access
      - OPENVPN_USER=${GLUETUN_OPENVPN_USER}
      - OPENVPN_PASSWORD=${GLUETUN_OPENVPN_PASS}
      - REGION=DE Frankfurt
      - PORT_FORWARDING=on
      - PROTOCOL=udp
      - PIA_ENCRYPTION=strong
      - PUID=${PUID}
      - PGID=${PGID}
      - TZ=${TZ}
    ports:
      # HOST:CONTAINER
      # TCP if not specified
      # qBittorrent
      - 6881:6881
      - 6881:6881/udp
      - 8080:8080

      # This doesn't work, just shows JDownloader on both ports

      # Firefox
      - 5800:5800
      # JDownloader
      - 5801:5800

      # I also tried using the `ports` section down at JDownloader to remap the port
      # "before" routing the connection through gluetun (and then using `5801:5801` for JDownloader here) 
      # but `network_mode` and `ports` can't be used at the same time

    volumes:
      - gluetun:/gluetun
    restart: unless-stopped

  qbittorrent:
    container_name: qbittorrent
    image: linuxserver/qbittorrent
    network_mode: service:gluetun
    environment:
      - PUID=${PUID}
      - PGID=${PGID}
      - TZ=${TZ}
      - UMASK_SET=022
      - WEBUI_PORT=8080
    volumes:
      - qbittorrent:/config
      - downloads:/downloads
    restart: unless-stopped

  firefox:
    container_name: firefox
    image: jlesage/firefox
    network_mode: service:gluetun
    shm_size: 2g
    environment:
      - USER_ID=${PUID}
      - GROUP_ID=${PGID}
      - TZ={TZ}
    volumes:
      - firefox:/config
      - downloads:/downloads
    restart: unless-stopped

  rclone:
    container_name: rclone
    image: rclone/rclone
    command: rcd --rc-web-gui --rc-addr :5572 --rc-user ${RCLONE_USER} --rc-pass ${RCLONE_PASS}
    environment:
      - PUID=${PUID}
      - PGID=${PGID}
      - TZ=${TZ}
    ports:
      - 5572:5572
    volumes:
      - rclone:/config/rclone
      - rclone:/data
      - downloads:/downloads
    restart: unless-stopped

  jdownloader:
    container_name: jdownloader
    image: jlesage/jdownloader-2
    network_mode: service:gluetun
    environment:
      - USER_ID=${PUID}
      - GROUP_ID=${PGID}
      - TZ={TZ}
    volumes:
      - jdownloader:/config
      - downloads:/output

volumes:
  gluetun:
  qbittorrent:
  downloads:
  firefox:
  rclone:
  jdownloader:

Thank you!

slugger7 commented 3 years ago

What I am currently doing is just spinning up 2 separate gluetun containers where one is mapped to a different port. I would like to only use one container for both but this solution works for now.

qdm12 commented 3 years ago

There is no nice workaround really. The easiest would be to build your own image using FROM officialimagename and modify the port yourself, or do a PR to the repo of that docker image to support a dynamic internal port. I'll try to do that PR in the coming days. Maybe you can help me find what's the corresponding Github repository? Thanks!

lx30011 commented 3 years ago

Thanks for the workaround, I didn't know about the FROM instruction.

The two images mentioned are maintained at the two following repos:

Although it should be noted that this particular developer maintains a LOT of docker images and all of them suffer under this issue.

Thank you for doing this!

qdm12 commented 3 years ago

I had a quick look on my phone and it doesn't seem obvious where it's defined but I'll try again over the weekend 😉

qdm12 commented 3 years ago

The author told me he's reworking the base image common to all his images to have this port configurable. If you don't mind, as I'm also low on time/energy 😄, subscribe to https://github.com/jlesage/docker-jdownloader-2/issues/70 so that you can be alerted when this is possible and I'll close this issue. Thanks!

Daniel-Kalus commented 3 years ago

I've run into the same problem, with jlesage/jdownloader-2 and jlesage/mkvtoolnix, both are using port 5800 and I think the author hasn't made the port configurable yet.

There is no nice workaround really. The easiest would be to build your own image using FROM officialimagename and modify the port yourself

Could you elaborate on this or maybe point me to a documentation where it is explained how to do this? I'm new to docker and only used docker-compose files to spin up images from the docker hub. Thanks!

ChrizZz90 commented 3 years ago

not a solution but a workaround, for JD2 use https://hub.docker.com/r/antlafarge/jdownloader

You can change the port for JD

qdm12 commented 3 years ago

Thanks @ChrizZz90 Unfortunately there is no workaround since they run on the same host, AFAIK.