jittering / traefik-kop

A dynamic docker->redis->traefik discovery agent
MIT License
179 stars 13 forks source link

Doesn't work with multiple services on one container #14

Closed dorianim closed 1 year ago

dorianim commented 2 years ago

Currently, there is a problem when configuring multiple routers on one container. For example:

minio:
  image: quay.io/minio/minio
  volumes:
    - ./minio:/data
  ports:
    - 9000:9000
    - 9001:9001
  command:
    - server
    - /data
    - --console-address
    - ":9001"
  environment:
    MINIO_ROOT_USER: root
    MINIO_ROOT_PASSWORD: root
  labels:
    traefik.enable: true
    traefik.http.routers.s3.rule: "Host(`s3.example.com`)"
    traefik.http.routers.s3.entrypoints: webs
    traefik.http.services.s3.loadbalancer.server.port: 9000

    traefik.http.routers.minio.rule: "Host(`minio.example.com`)"
    traefik.http.routers.minio.entrypoints: webs
    traefik.http.services.minio.loadbalancer.server.port: 9001

It would be really nice to get this working, as it is a bit annoying to put the second one into a different config file :)

Regards, Dorian

hongkongkiwi commented 1 year ago

Please could you look into this? I'm also keen on this feature :)

chetan commented 1 year ago

@dorianim @hongkongkiwi I just tested this locally and it appears to work without issue. See this sample compose file where I just added an example of a service with multiple ports exposed.

Here's the output when I bring up that service:

time="2022-09-10T14:36:00-04:00" level=info msg="refreshing traefik-kop configuration"
time="2022-09-10T14:36:00-04:00" level=warning msg="found more than one host-port binding for container '/testing-helloworld-1' (5555:5555, 5566:5566)" service=hello2@docker service-type=http
time="2022-09-10T14:36:00-04:00" level=info msg="publishing http://1.2.3.4:5566" service-type=http service=hello2@docker
time="2022-09-10T14:36:00-04:00" level=warning msg="found more than one host-port binding for container '/testing-helloworld-1' (5555:5555, 5566:5566)" service=hello1@docker service-type=http
time="2022-09-10T14:36:00-04:00" level=info msg="publishing http://1.2.3.4:5555" service=hello1@docker service-type=http

Could you provide some more info regarding what you're seeing traefik-kop do? I'm pushing a new version shortly which adds some extra logging around port detection that might help sort out your issue.

dorianim commented 1 year ago

Ok, nevermind, I just forgot do define the service name. It works like this:

minio:
  image: quay.io/minio/minio
  volumes:
    - ./minio:/data
  ports:
    - 9000:9000
    - 9001:9001
  command:
    - server
    - /data
    - --console-address
    - ":9001"
  environment:
    MINIO_ROOT_USER: root
    MINIO_ROOT_PASSWORD: root
  labels:
    traefik.enable: true
    traefik.http.routers.s3.rule: "Host(`s3.example.com`)"
    traefik.http.routers.s3.entrypoints: webs
    traefik.http.routers.s3.service: s3
    traefik.http.services.s3.loadbalancer.server.port: 9000

    traefik.http.routers.minio.rule: "Host(`minio.example.com`)"
    traefik.http.routers.minio.entrypoints: webs
    traefik.http.routers.minio.service: minio
    traefik.http.services.minio.loadbalancer.server.port: 9001