Docker container cannot connect to host machine: No route to host

10,588

To my surprise, it was actually a firewall issue in my case.

Update/Enable the tcp port [2375] on the docker host machine fixes the issue.

sudo firewall-cmd --zone=public --add-port=2375/tcp --permanent

sudo firewall-cmd --reload 

useful links: 1. enter link description here 2. enter link description here

Share:
10,588
Brian DiCasa
Author by

Brian DiCasa

Web application developer with a passion for technology. Focus on web standards and server architectures. Enjoy the creation of complex applications that push the boundaries of what the web can do. Specialties include: Web Applications, Java, Server Architectures, Web Standards (HTML, CSS, JavaScript), JavaScript Libraries/Frameworks

Updated on June 15, 2022

Comments

  • Brian DiCasa
    Brian DiCasa almost 2 years

    I've been trying to setup a docker environment using docker compose. One issue that has me stumped is that my docker containers cannot reach my host machine.

    I setup a container using the following compose file:

    version: '3'
    services:
      webapp:
        image: ...
        ports:
          - "8080:8080"
    

    When I enter the container, I am able to ping my host machine:

    ping ${dockerHostIP}
    

    However when I try and retrieve the home page using curl inside the container:

    curl http://${dockerHostIP}:8080
    

    I get:

    curl: (7) Failed connect to ${dockerHostIP}:8080; No route to host
    

    I cannot figure out what should be done to resolve this No route to host error. Unfortunately I need to be able to do this as the web application makes requests using its hostname internally.

    Traceroute Results:

    traceroute ${dockerHostIP}
    traceroute to ${dockerHostIP} (${dockerHostIP}), 30 hops max, 60 byte packets
     1  ${dockerHostName} (${dockerHostIP})  0.039 ms !X  0.012 ms !X  0.007 ms !X