Traefik on docker generating service pointing to localhost

Hi!
I'm new to Traefik and I'm using it on my VPS to serve some API/Frontends.
I'm struggling to run my java/spring api that has this docker-compose config for traefik:

labels:
      #  I'm keeping it false till solve the service auto creating
      - "traefik.enable=true"
      - "traefik.http.routers.api-java.rule=Host(`myHost`) && PathPrefix(`/`)"
      - "traefik.http.routers.api-java.entrypoints=https"
      - "traefik.http.routers.api-java.tls.certResolver=letsencrypt"
      - "traefik.http.routers.api-java.tls.domains[0].main=myHost"
      - "traefik.http.routers.api-java.middlewares=redirect-to-https"
      - "traefik.http.routers.api-java.service=api-java-backend"
      - "traefik.http.services.api-java-backend.loadbalancer.server.port=8081"
      - "traefik.http.services.api-java-backend.loadbalancer.server.url=http://<my_vps_ip>:8081/"
      - "traefik.http.services.api-java-backend.loadBalancer.passHostHeader=true"
      - "traefik.http.middlewares.redirect-to-https.redirectScheme.scheme=https"

When I run this docker-compose, traefik creates 2 services, this one I'm asking for, and the docker automatic service, that points to server.url = 172...:8081 (localhost docker url serving my API).

To temporally solve this I created the router and service on my main.yaml file (traefik config file) like this:

Router:

"api-java" : {
        "service": "api-java",
        "rule": "Host(`<myHost>`) && PathPrefix(`/`)",
        "middlewares": [
          "redirect-to-https"
        ],
        "tls" : {
          "certResolver": "letsencrypt",
          "domains": [
            "main": "<myHost>"
          ]
        },
        "entryPoints": [
          "https"
        ]
      }

Service:

"api-java": {
        "loadBalancer": {
          "servers": [
            {
              "url": "http://<my_vps_ip>:8081/"
            }
          ],
          "passHostHeader": true
        }
      },

I want the service and router to be correctly dynamic created, from my docker-compose file, but cant reach this while traefik on docker keeps creating a service everytime, I need help for this, can someone help me?

Obs: Traefik was auto-installed by easypanel on my VPS, thats why I'm using it
Ob2: By this docs --> Custom Traefik Configuration | Easypanel I know I can make a custom config yaml, but I'm afraid to mess something w it

can not be used in Docker service/container labels, as the target service is always the service/container with the labels attached to it.

Usually you would place Traefik and target service within the same Docker network, check simple Traefik example.

1 Like

Hi! Ty for ur answer.
I tryied to point it for the docker network and still not working so I just changed my services and now I'm providing the configs on my conf.yml from traefik instead of using dinamic config