无法连接到Docker实例中的HBase

我创build了一个在Docker容器上运行的HBase实例。 我已经能够使用Docker容器的bash shell从HBase Shell中创build一个表,并且能够从HBase Rest API访问它。

但是我无法使用Scala从Play框架访问它,我经常会遇到以下exception。

MasterNotRunningException |com.google.protobuf.ServiceException: java.net.UnknownHostException: unknown host: 238b057263fb 

这是抛出exception的Scala代码。

 val config = HBaseConfiguration.create() var hbaseRunning = false; config.clear config.set("hbase.zookeeper.quorum", "172.18.0.2"); // This ip Address was retrieved by doing a docker inspect on the docker container config.set("hbase.zookeeper.property.clientPort","2181") config.set("hbase.master", "172.18.0.2:60000"); config.setInt("timeout", 25000); try{ println(" Check if HBase is Running") HBaseAdmin.checkHBaseAvailable(config); // This line throws the exception println(" HBase is Running") // Because this line doesnt print. hbaseRunning = true }catch{ case ex: MasterNotRunningException => { println(" MasterNotRunningException |" + ex.getMessage) // This is the exception I get } } finally println(" HBase is NOT Running") 

这里是Hbase-Site.xml

 <configuration> <property> <name>hbase.tmp.dir</name> <value>file:///opt/hbasedata</value> </property> 

编辑:我的Docker文件是一个较大的docker组成的一部分,我发布docker端口。 docker组成部分中的端口部分如下

  ports: - 2181:12181 - 60000:60000 - 60010:60010 - 60020:60020 - 60030:60030 - 2471:2471 // this is for the rest API 

我能够访问HBase并从Shell和Rest API中操作数据,只有使用Java API的Play Framework的访问失败。 我哪里错了?

看起来您的Dockerized群集正在通过Dockernetworking内的主机名跟踪主服务器。

您或者需要:

  1. 在该networking的容器中运行您的Play应用程序(以便它可以parsing主控主机名)

要么

  1. 使用-h <hostname> (或等效的组合标记)启动容器,并确保您的Play服务器将该主机名映射到正确的IP(通过/etc/hosts或DNS)。 -h选项将导致您的群集向主控制器报告一个内部(对于Dockernetworking)fqdn,而Play侧的映射会将您的Play应用程序从内部fqdn指向实际地址。

如果要从容器外部访问容器端口,则在运行docker run ~时,需要使用-p <host port>:<guest port>来发布这些端口。