prometheus inside docker not scraping node_exporter

I installed prometheus with docker using the official guide on their page.
Now I also have node_exporter working on the host. Yet prometheus doesn’t seem to scrape metrics of it.

I run prometheus using:

sudo docker run -d -p 9090:9090 -v /home/main/prometheus/config.yml:/etc/prometheus/prometheus.yml prom/prometheus

  - job_name: node
      - targets: ['localhost:9100']
curl -i localhost:9100
HTTP/1.1 200 OK

Content-Length: 150
Content-Type: text/html; charset=utf-8

<head><title>Node Exporter</title></head>
<h1>Node Exporter</h1>
<p><a href="/metrics">Metrics</a></p>

enter image description here


apparently, this is fixed using the "-net=host" flag when running on docker:
sudo docker run --net=host -d -p 9090:9090 -v /home/main/prometheus/config.yml:/etc/prometheus/prometheus.yml prom/prometheus

Source: Docker Questions