Docker容器无法连接到主机:没有路由到主机 [英] Docker container cannot connect to host machine: No route to host
问题描述
我一直在尝试使用docker compose设置docker环境。让我感到困扰的一个问题是我的docker容器无法访问我的主机。
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"
当我进入容器时,可以对主机进行ping操作机器:
When I enter the container, I am able to ping my host machine:
ping ${dockerHostIP}
但是,当我尝试使用容器内的curl检索主页时:
However when I try and retrieve the home page using curl inside the container:
curl http://${dockerHostIP}:8080
我知道了:
curl: (7) Failed connect to ${dockerHostIP}:8080; No route to host
我无法弄清楚该如何解决此无托管路径错误。不幸的是,由于Web应用程序在内部使用其主机名发出请求,因此我必须能够做到这一点。
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结果:
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
推荐答案
令我惊讶的是,这实际上是我的防火墙问题。
To my surprise, it was actually a firewall issue in my case.
在Docker主机上更新/启用tcp端口[2375]
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
有用的链接:
1. 在此处输入链接描述
2. 在此处输入链接描述
这篇关于Docker容器无法连接到主机:没有路由到主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!