jittering / traefik-kop

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

Fix: Automatic port assignment not working for containers without a service #3

Closed dorianim closed 2 years ago

dorianim commented 2 years ago

There is an issue with the new automaic port detection introduced in #2 which this PR aims to fix: When you have a container /opt/nginx/docker-compose.yml like this:

services:
  nginx:
    ports:
     - 1234:80
    labels:
      traefik.enable: true
      traefik.http.routers.nginx.rule: "Host(`example.com`)"
      traefik.http.routers.nginx.entrypoints: web-secure

The current detection of 1234 as the port fails, because it looks for traefik.http.services.nginx-nginx (traefik assigns nginx-nginx as a service name) in the container labels. So I added a check which finds the router of the service and then searches for traefik.http.nginx.

What do you think?

dorianim commented 2 years ago

I also added a unit test which catches this problem :)