宿主机无法访问容器内的zookeeper服务
2017-05-30 17:58:20
钱龙
  • 访问次数: 4
  • 注册日期: 2015-09-10
  • 最后登录: 2017-06-26
CentOS 6系统上安装了Docker 1.7,安装并运行了zookeeper容器,容器内服务可正常运行。但是运行容器时如果使用`docker run -d -p 12181:2181 --name zookeeper daocloud.io/library/zookeeper`运行,则宿主机上使用zkCli.sh -server localhost:12181不能正常连接,报错如下:

{{{
2017-05-30 17:40:50,937 [myid:] - INFO  [main-SendThread(10.11.20.30:2181):ClientCnxn$SendThread@1032] - Opening socket connection to server 10.11.20.30/10.11.20.30:2181. Will not attempt to authenticate using SASL (unknown error)
JLine support is enabled
[zk: 10.11.20.30:2181(CONNECTING) 0] 2017-05-30 17:40:53,954 [myid:] - WARN  [main-SendThread(10.11.20.30:2181):ClientCnxn$SendThread@1162] - Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect
java.net.NoRouteToHostException: No route to host
        at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
        at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:744)
        at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361)
        at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1141)
}}}

如果我使用`docker run -d --net=host --name zookeeper daocloud.io/library/zookeeper`运行时,则可以正常连接,宿主机的防火墙已经关闭,请教下大家,默认使用bridge模式为啥不行?另外我在Mac笔记本上使用bridge模式是没有问题,不同的是docker版本是1.12,这可能是docker版本的问题吗?