How to define more than 1 port for a container in docker-compose?

I am getting the hang of traefik, thanks to all the wonderfull help i get here.
Just one more question :slight_smile:

all my containers with a single port are working if I define the single port like this in the docker-compose of the container

- '"{{ DOCKER_NAME }}".loadbalancer.server.port=80'

but what i am now struggeling with are the containers that are using more than 1 port.

If i wanted to add for example port 80 and 81 to a docker-compose file, how do I do that?

- '"whoami".loadbalancer.server.port=80'
- '"whoami".loadbalancer.server.port=81'
  • I know whoami does not run on port 81, but it is just an example

does not work, because traefik will only look at the last port defined in the docker-compose file
I searched topics on this community but most of them are for http and https ports so that is a different url

I want multiple ports to use just the http connection for example

Hello @uinguzero

Thanks a lot for using Traefik and asking the question.

Seems you need to create another router and service and bind the service with the newly created router accordingly, see the referring example below:

      - "traefik.enable=true"
      - "traefik.http.routers.whoami.rule=host(``)"
      - "traefik.http.routers.whoami.entrypoints=web"
      - ""
      - "traefik.http.routers.whoami.service=whoami"

      - "traefik.http.routers.whoami2.rule=host(``)"
      - "traefik.http.routers.whoami2.entrypoints=web"
      - ""
      - "traefik.http.routers.whoami2.service=whoami2"

I hope that helps, let me know :wink:

But these have both different rules/routes

If a single docker container needs to use several ports like a unifi controller, how do you point different ports to the same route ?