I have a docker container as part of docker-compose that should reach other containers but as well a server running in my local network.
(the docker container is a monitoring service)

I know that in order to reach the local LAN I should configure the network mode to “host”, is that correct? In that case am I still able to reach the other containers running in the default bridge network?

  • trabiko@alien.topB
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    You should be able to reach local network running in bridge mode, here’s a test from my local server pinging the laptop, executed in a docker container

    root@dalek:/# ping -c1  192.168.8.167  
    PING 192.168.8.167 (192.168.8.167): 56 data bytes  
    64 bytes from 192.168.8.167: seq=0 ttl=64 time=0.440 ms  
    \--- 192.168.8.167 ping statistics ---  
    1 packets transmitted, 1 packets received, 0% packet loss  
    round-trip min/avg/max = 0.440/0.440/0.440 ms  
    root@dalek:/# ip route get 192.168.8.167  
    192.168.8.167 dev eno1  src 192.168.8.136
    
    

    Host mode exposes the listening ports of the container as they were services on the machine, so iptables doesn’t do any mangling of traffic where to send connection to port XY to which container.

    • not-the-real-chopin@alien.topOPB
      link
      fedilink
      English
      arrow-up
      1
      ·
      1 year ago

      Thanks, it must have been some other problem. I’m able to reach my local network from within the docker container. I even found that the docker container is using the host DNS configuration.

      I configured pi.hole as DNS server in the host machine and the docker container is using it too.

  • isleepbad@alien.topB
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    No that’s not correct. You don’t need to be in host mode to access the local LAN.

    • maximus459@alien.topB
      link
      fedilink
      English
      arrow-up
      1
      ·
      1 year ago

      This, mnn… but if you want to know who a reply is from you should be on the hike Ian right?

  • thekrautboy@alien.topB
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    I know that in order to reach the local LAN I should configure the network mode to “host”, is that correct?

    No, that has nothing to do with that.

    In that case am I still able to reach the other containers running in the default bridge network?

    No, using network_mode host makes it more complicated to also reach other containers on the same Docker host.

    Why not ask /r/Docker and read the Docker documentation?