Search code examples
nginxdocker-composedocker-network

nginx-prometheus-exporter container cannot connect to nginx


I have a docker-compose and both nginx and nginx-prometheus-exporter are containers. I put the relevant parts here:

  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 http://nginx:8080/stub_status, nginx:8080/stub_status and 127.0.0.1:8080/stub_status for -nginx.scrape-uri but none of them worked and I got 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