在 docker-compose 文件中设置参数

Setting arguments in docker-compose file

您好,我想在 docker 容器中使用此处 https://github.com/prometheus/haproxy_exporter 提供的 haproxy 导出器。

我正在使用 docker-compose 管理容器并想重新创建此命令:

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

在我的 docker-compose.yml.

我不确定如何传递参数,在查看 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"

但这给了我一个 file is invalid 消息,因为它需要一个带有构建的上下文。

提前感谢您的帮助

图像已经构建并从集线器中提取(除非您有自己的 Dockerfile),因此您不需要构建选项。相反,将您的参数作为命令传递,因为图像似乎使用入口点(如果他们的 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"