Docker Community Forums

Share and learn in the Docker community.

Communication between container running in network_mode=host and other containers running on other network

Hello,

I’m running Prometheus node_exporter in network_mode=host, the reason is to monitor all NW interfaces.
All other containers (including Prometheus) are running on dedicated NW (net)
the problem - port of node_exporter container is not reachable from other containers

ping from Prometheus container to IP that node_exporter has is working fine

ping 172.31.0.1
PING 172.31.0.1 (172.31.0.1): 56 data bytes
64 bytes from 172.31.0.1: seq=0 ttl=64 time=0.086 ms
64 bytes from 172.31.0.1: seq=1 ttl=64 time=0.091 ms

when wget is failing

wget 172.31.0.1:9194
Connecting to 172.31.0.1:9194 (172.31.0.1:9194)
wget: can't connect to remote host (172.31.0.1): Operation timed out

of cause from the host everything is working fine

wget 172.31.0.1:9194
--2021-07-28 09:22:14--  http://172.31.0.1:9194/
Connecting to 172.31.0.1:9194... connected.
HTTP request sent, awaiting response... 200 OK

Prometheus container interfaces

eth0      Link encap:Ethernet  HWaddr 02:42:AC:1F:00:02  
          inet addr:172.31.0.2  Bcast:172.31.0.255  Mask:255.255.255.0

Node exporter container interfaces

br-1ad4556bf2df Link encap:Ethernet  HWaddr 02:42:05:50:9F:FA  
          inet addr:172.31.0.1  Bcast:172.31.0.255  Mask:255.255.255.0
          inet6 addr: fe80::42:5ff:fe50:9ffa/64 Scope:Link

docker0   Link encap:Ethernet  HWaddr 02:42:EA:A0:83:0B  
          inet addr:172.17.0.1  Bcast:172.17.255.255  Mask:255.255.0.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1

ens4      Link encap:Ethernet  HWaddr 42:01:0A:84:00:0B  
          inet addr:10.132.0.11  Bcast:0.0.0.0  Mask:255.255.255.255

from docker-compose

  prometheus_node_exporter:
    network_mode: host
    command:
      - '--web.listen-address=:9194'
..........................
  prometheus:
    networks:
        - net
...............................
networks:
    net:
        ipam:
            driver: default
            config:
                - subnet: 172.31.0.0/24

any ideas?