Docker container cannot connect to host machine: no route to host
I am trying to set up a docker environment using docker compose. One issue that puzzled me is that my docker containers cannot reach my main machine.
I am setting up a container using the following compose file:
version: '3'
services:
webapp:
image: ...
ports:
- "8080:8080"
When I enter the container, I can ping my host machine:
ping ${dockerHostIP}
However, when I try to restore 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 needs to be done to resolve this error. Unfortunately, I have to be able to do this as the web app 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
+3
source to share
1 answer
To my surprise, in my case it was a firewall issue.
Updating / enabling tcp port [2375] on the docker host 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 here
0
source to share