Traefik and my web app inside a container

I am trying to do something I thought was simple, but looks like I’m missing a thing.

I have a web app, which is package in a docker image I manage. It starts a server listening on port 9000. It does have an endpoint publishing metrics, on /admin/metrics.
The application is deployed on a system that requires me to publish those metrics on port 9100, with the path /metrics. I could change the application, run a second server, etc, but for fun I tried something quicker (I thought): running a companion reverse proxy.

I chose traefik, and I managed to configure it properly using a file provider: when running on my machine (no container), it does redirect properly calls from /metrics on port 9100 to my app’s /admin/metrics. But when inside the container, it only gives 404 errors, although the configuration is ok. I also tried to run the app only and have traefik on my machine route to the app inside the container, but it fails too.

This is my configuration:

    address = ":9100"

  providersThrottleDuration = 42
    directory = "/app"
    watch = false

  insecure = false
  dashboard = false
  debug = false

  level = "TRACE"
      entryPoints = ["MetricsProxy"]
      middlewares = ["PathConvert"]
      service = "MetricsService"
      rule = "Path(`/metrics`)"
          url = ""
        prefix = "/admin"

Please note that I tried to replace with or localhost, neither works.

Finally, the Dockerfile:

FROM openjdk:8-jre-slim


  apt-get update -qq && apt-get install -y -qq curl && 
  curl -sSL | tar -xz

COPY bin/ .
COPY target/universal/ .
COPY deploy/traefik/traefik.toml .
COPY deploy/traefik/metrics.toml .
COPY deploy/nginx.conf .
COPY deploy/ . ~~> ./traefik --configfile /app/traefik.toml & ./
CMD [ "/app/" ]

I guess there is something with “localhost” in the service definition, but cannot understand what.

Anyone has an idea?

Source: StackOverflow