容器中的Traefik和我的Web应用程序

我正在尝试做一些我认为很简单的事情,但看起来好像我错过了一件事情。

我有一个Web应用程序,该应用程序打包在我管理的Docker映像中。它启动服务器侦听端口9000。它在/admin/metrics上具有端点发布指标。 该应用程序已部署在要求我使用路径/metrics在端口9100上发布这些度量的系统上。我可以更改应用程序,运行第二台服务器,等等,但是为了好玩,我尝试了一些更快的操作(我认为):unning运行同伴反向代理。

我选择了traefik,并设法使用文件提供程序正确配置了它:在计算机上运行(无容器)时,它确实将端口9100上的/metrics的调用正确重定向到应用程序的{{1} }。但是,尽管配置还可以,但在容器内部时,它只会给出404错误。我还尝试仅运行该应用程序,并且在通往容器内该应用程序的机器路由上出现了traefik,但它也失败了。

这是我的配置:

/admin/metrics
#/app/traefik.toml
[entryPoints]
  [entryPoints.MetricsProxy]
    address = ":9100"

[providers]
  providersThrottleDuration = 42
  [providers.file]
    directory = "/app"
    watch = false

[api]
  insecure = false
  dashboard = false
  debug = false

[log]
  level = "TRACE"

请注意,我尝试将#/app/metrics.toml [http] [http.routers] [http.routers.Router0] entryPoints = ["MetricsProxy"] middlewares = ["PathConvert"] service = "MetricsService" rule = "Path(`/metrics`)" [http.services] [http.services.MetricsService] [http.services.MetricsService.loadbalancer] [[http.services.MetricsService.loadBalancer.servers]] url = "http://0.0.0.0:9000" [http.middlewares] [http.middlewares.PathConvert] [http.middlewares.PathConvert.addPrefix] prefix = "/admin" 替换为0.0.0.0127.0.0.1,但均无效。

最后,localhost

Dockerfile

我猜在服务定义中有一些带有“ localhost”的东西,但是不知道是什么。

有人有主意吗?

csz802864 回答:容器中的Traefik和我的Web应用程序

不确定为什么会这样工作,但是我成功地为traefik使用了另一种配置:

[http]
  [http.routers]
    [http.routers.Router0]
      entryPoints = ["MetricsProxy"]
      middlewares = ["PathConvert"]
      service = "MetricsService"
      rule = "Path(`/metrics`)"
  [http.services]
    [http.services.MetricsService]
      [http.services.MetricsService.loadbalancer]
        [[http.services.MetricsService.loadBalancer.servers]]
          url = "http://localhost:9000/"
  [http.middlewares]
    [http.middlewares.PathConvert]
      [http.middlewares.PathConvert.replacePathRegex]
        regex = "^/metrics"
        replacement = "/admin/metrics/prometheus"
本文链接:https://www.f2er.com/3146345.html

大家都在问