Hello everybody! I have the following issue: I have two countainers, let’s call them C1 and C2, and they both expose the same port, let’s say 1234. I want to route both of them through a gluetun container. to do this, I added

network_mode: container:gluetun

at each container. But they both expose the same port, so there’s a conflict. Without routing them though gluetun I can just

ports:
  - 1235:1234

but using network_mode this cannot be done. What can I do? The only thing that comes to my mind is to use two gluetun containers, but I’d rather use a single one

thanks in advance!

  • @Fedegenerate@lemmynsfw.com
    link
    fedilink
    English
    5
    edit-2
    1 month ago

    On mobile so you’ll have to forgive format jank.

    It depends how each image handles ports if C1 has the ports set up as 1234:100 and C2 has the ports set up as 1234:500 then:

    service:

    gluetun:

    ports:

     - 1234:100 #c1
     - 1235:500 #c2
    

    […]

    Will solve the conflict

    Sometimes an image will allow you to edit it’s internal ports with an environment so

    service:

    gluetun:

    ports:

      - 1234:1000 #c1
      -1235:1234 #c2
    

    c1:

    environent:

    - UI_PORT=1000
    

    […]

    When both contsiners use the same second number, C1: 1234:80, C21235:80, and neither documents suggest how to change that port, I personally haven’t found a way to resolve that conflict.

    • tubbaduOP
      link
      English
      230 days ago

      thanks for the detailed reply!

      When both contsiners use the same second number, C1: 1234:80, C21235:80, and neither documents suggest how to change that port, I personally haven’t found a way to resolve that conflict.

      unfortunately I’m in this situation, so I guess my only ways are to modify the container by hand or to create two instances of gluetun. thank you very much for your help!

  • @emax_gomax@lemmy.world
    link
    fedilink
    English
    41 month ago

    I funnily had the same use case. Two different jellyfin servers for complete separation. Both routing through gluetun. The reason this doesn’t work is because the network mode setting you have basically makes all three containers operate in the same network. Meaning if one binds a port the others can no longer bind the same port. Their different hosts but all sharing one network and port range. To expose the ports you can move that ports setting from C1/C2 to the gluetun service definition. This’ll still work because when C1 binds to 1234 it’ll be reachable through the gluetun service.

    Note: as mentioned if C1 and C2 cannot use the same port if you also want to have service gluetun set. More likely than not you start C1, it binds to the port, start C2, it tries and fails to bind to the port and crashes. I fixed this by making one of my jellyfin containers use a separate port. If you can’t configure the ports of your services then there’s no real recourse FWIU.

    • tubbaduOP
      link
      English
      130 days ago

      If you can’t configure the ports of your services then there’s no real recourse FWIU

      Sadly this is my case… I guess I’ll have to give up then thank you very much!

    • tubbaduOP
      link
      English
      130 days ago

      thanks for the reply! many services allows this by setting an environmental variable or through a config file, but sadly not all of them

  • Onno (VK6FLAB)
    link
    fedilink
    English
    21 month ago

    The port number on the outside doesn’t have to be the same as the port number on the inside.