3
votes

I would like to have Prometheus and Grafana running on my developer machine using docker-images / docker-for-windows.

I have system-under-development, ASP.Net core, running on localhost:5001 and metrics are showing just fine on https://localhost:5001/metrics.

Docker-compose.yml and prometheus.yml listed below.

  • If I include network_mode: host in docker-compose.yml, I can't access Prometheus on my physical machine via localhost:9090
  • If I exclude network_mode and instead use ports: , I can access Prometheus on my physical machine via localhost:9090, but checking http://localhost:9090/targets, it shows https://localhost:5001/metrics as being down.

What am I doing wrong? Any comments welcome!

docker-compose.yml:

version: '3.8'
services:
  prometheus:
    image: prom/prometheus
    container_name: gradle_docker-prometheus
    #network_mode: host
    ports:
      - 9090:9090
    volumes:
      - prometheus-storage:/var/lib/prometheus
      - /c/Data/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
  grafana:
    image: grafana/grafana
    container_name: gradle_docker-grafana
    ports:
      - "3000:3000"
    volumes:
      - grafana-storage:/opt/grafana/data
    depends_on:
      - prometheus

volumes:
  prometheus-storage: {}
  grafana-storage: {}

prometheus.yml:

global:
  scrape_interval:     15s
  evaluation_interval: 15s

  external_labels:
      monitor: 'my-project'

scrape_configs:
  - job_name: 'prometheus'
    scrape_interval: 10s
    scheme: http
    static_configs:
         - targets: ['localhost:9090','cadvisor:8080','node-exporter:9100', 'nginx-exporter:9113']
  - job_name: '.Net'
    scrape_interval: 10s
    scheme: https
    static_configs:
         - targets: ['localhost:5001']
1

1 Answers

0
votes

Do not use host network mode on Windows, it is only supported on Linux. What you need is to change target address:

  - job_name: '.Net'
    scrape_interval: 10s
    scheme: https # You may have to change this to 'http'
                  # or you'd have to create a certificate 
                  # with `host.docker.internal`
    static_configs:
         - targets: ['host.docker.internal:5001']

host.docker.internal is a special address to connect to the Docker Host, since localhost inside a container is the container.