nginxdocker-composedocker-network

nginx-prometheus-exporter container cannot connect to nginx


I have a Docker Compose file with NGINX and nginx-prometheus-exporter as containers. Here are the relevant parts:

  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

I tried to use the below options for -nginx.scrape-uri, but none of them worked.

I got the error

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

Also, the localhost:8080/stub_status is available in my VM using cURL.


Solution

  • the problem was the missing -.

     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