Can't connect to Docker user defined bridge network

Viewed 16

I've been struggling with this for a while, maybe someone might have some insight...I've created a docker bridge network:

docker network create -d bridge prometheus-network

in which I'm running both Prometheus and cAdvisor containers, created as such: Prometheus:

docker run -d --net=prometheus-network --name=prometheus-server -p 9090:9090 -v /etc/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus 

cAdvisor:

docker run -d --net=prometheus-network --name=cadvisor -p 8080:8080 --volume=/:/rootfs:ro --volume=/var/run:/var/run:ro --volume=/sys:/sys:ro --volume=/var/lib/docker/:/var/lib/docker:ro --volume=/dev/disk/:/dev/disk:ro --privileged --device=/dev/kmsg gcr.io/cadvisor/cadvisor:latest

I can see both up and running and can connect to the Prometheus web UI. From there, though, it shows the cAdvisor connection being refused (I have one other container in the network as well, which is also being refused)

here is the prometheus.yml file, with the two targets defined:

global:
  evaluation_interval: 15s
  scrape_interval: 15s
scrape_configs:
  - job_name: adapters
    static_configs:
      - labels:
          namespace: adapters
        targets:
          - tiingo:9080
  - job_name: cadvisor
    static_configs:
      - targets: ['localhost:8080']

and what I'm seeing: enter image description here

Is there some other networking step here that I might be missing?? Thanks in advance for any help...

1 Answers

When you connect to localhost you will connect to the localhost of the current container. Within user-defined docker networks you can use container names as hostnames thanks to Docker service discovery.

So use cadvisor:8080 instead of localhost:8080 in your configuration file.

Related