来自Docker容器的出站Telnet连接被拒绝,但在主机上正常工作

我在通过Tutum to AWS托pipe的节点上遇到networking问题。

我进入了节点并跑了

telnet localhost 3000

而且效果很好。 当我将docker exec -it <containerid> bash放到我的一个容器中并运行上面的命令时,我得到这个错误:

telnet: Unable to connect to remote host: Connection refused

谁能阐明为什么出站连接从容器到主机是不允许的?

你的容器使用什么networking堆栈? localhost意味着本地。 在你的主机上它是主机本地接口,你的容器是它们自己的主机本地接口。 所以,除非你使用--net=host来运行你的容器, --net=host这是一个常规的行为,因为没有服务在containers-localhost-ip:3000上运行,但只在host-localhost-ip:3000上有所不同。