Warm tip: This article is reproduced from serverfault.com, please click

docker compose-nginx-prometheus-exporter容器无法连接到nginx

(docker compose - nginx-prometheus-exporter container cannot connect to nginx)

发布于 2020-11-22 09:22:44

我有一个docker-compose并且nginx和nginx-prometheus-exporter都是容器。我把相关的部分放在这里:

  nginx:
    container_name: nginx
    image: nginx:1.19.3
    restart: always
    ports:
      - 80:80
      - 443:443
      - "127.0.0.1:8080:8080"

  nginx-exporter:
    image: nginx/nginx-prometheus-exporter:0.8.0
    command:
      -nginx.scrape-uri
      -http://127.0.0.1:8080/stub_status

我试过 http://nginx:8080/stub_statusnginx:8080/stub_status127.0.0.1:8080/stub_status-nginx.scrape-uri但他们没有工作,我得到了Could not create Nginx Client: failed to get http://127.0.0.1:8080/stub_status: Get "http://127.0.0.1:8080/stub_status": dial tcp 127.0.0.1:8080: connect: connection refused

另外,在我的VM中,使用curl可以使用localhost:8080 / stub_status。

Questioner
no746
Viewed
11
no746 2020-11-30 16:15:30

问题是丢失了-

 nginx:
    container_name: nginx
    image: nginx:1.19.3
    restart: always
    ports:
      - 80:80
      - 443:443
      - "127.0.0.1:8080:8080"

  nginx-exporter:
    image: nginx/nginx-prometheus-exporter:0.8.0
    command:
      - -nginx.scrape-uri
      - http://127.0.0.1:8080/stub_status