简体   繁体   English

在 docker-compose 文件中设置参数

[英]Setting arguments in docker-compose file

Hi I want to use the haproxy exporter provided here https://github.com/prometheus/haproxy_exporter in a docker container.嗨,我想在 docker 容器中使用这里提供的 haproxy 导出器https://github.com/prometheus/haproxy_exporter

I am using docker-compose for managing containers and want to recreate this command:我正在使用docker-compose来管理容器并希望重新创建此命令:

$ docker run -p 9101:9101 prom/haproxy-exporter -haproxy.scrape-uri="http://user:pass@haproxy.example.com/haproxy?stats;csv"

in my docker-compose.yml.在我的 docker-compose.yml 中。

I am not sure how to pass the argument, after viewing the docker-compose documentation I tried it like this:我不知道如何传递参数,在查看了 docker-compose 文档后,我像这样尝试:

  haproxy-exporter:
    image: prom/haproxy-exporter
    ports:
      - 9101:9101
    network_mode: "host"
    build:
      args:
        - haproxy.scrape-uri="http://user:pass@haproxy.example.com/haproxy?stats;csv"

But this gives me an file is invalid message because it requires a context with a build.但这给了我一个file is invalid消息,因为它需要一个带有构建的上下文。

Thanks for any help in advance感谢您提前提供任何帮助

The image is already built and pulled from the hub (unless you have your own Dockerfile) so you don't need the build option.映像已经构建并从集线器中提取(除非您有自己的 Dockerfile),因此您不需要构建选项。 Instead, pass your arguments as the command since the image appears to use an entrypoint (if their Dockerfile only had a cmd option, then you'd need to also pass /bin/haproxy-exporter in your command):相反,将您的参数作为命令传递,因为图像似乎使用了一个入口点(如果他们的 Dockerfile 只有一个 cmd 选项,那么您还需要在您的命令中传递 /bin/haproxy-exporter ):

 haproxy-exporter:
    image: prom/haproxy-exporter
    ports:
      - 9101:9101
    network_mode: "host"
    command: -haproxy.scrape-uri="http://user:pass@haproxy.example.com/haproxy?stats;csv"

I m trying to make work this exporter, but I m having the same issue: 我正在努力使这个出口商工作,但是我遇到了同样的问题:

monitoring_haproxy-exporter.1.93xpdn67l4e6@worker1-xxx.com    | time="2019-11-11T16:22:01Z" level=error msg="Can't scrape HAProxy: Get http://localhost:1936/?stats: dial tcp 127.0.0.1:1936: connect: connection refused" source="haproxy_exporter.go:305"

This is how I wrote the service on the compose file: 这是我在撰写文件上编写服务的方式:

  haproxy-exporter:
    image: prom/haproxy-exporter
      ports:
        - 9101:9101
    command: --haproxy.scrape-uri=http://localhost:1936/?stats;csv
    networks:
      - backend

Any answer will be appreciated, thanks! 任何答案将不胜感激,谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM