title: Connect to HBase running in Docker
body: <p>I cannot connect to HBase running in Docker on Windows (<a href="https://registry.hub.docker.com/u/banno/hbase-standalone/" rel="noreferrer">banno/hbase-standalone</a> image). However, I can connect to locally installed HBase.</p>
  
  <p><a href="https://registry.hub.docker.com/u/banno/hbase-standalone/" rel="noreferrer">banno/hbase-standalone</a> image is run using:</p>
  
  <pre><code>docker run -d -p 2181:2181 -p 60000:60000 -p 60010:60010 -p 60020:60020 -p 60030:60030 banno/hbase-standalone
  </code></pre>
  
  <p>I also set up the port forwarding on the <code>boot2docker-vm</code> (which is required when running on Windows):
  <img src="https://i.stack.imgur.com/nax2A.png" alt="enter image description here"></p>
  
  <p>I can successfully telnet to all those ports on my localhost.</p>
  
  <p>Next, here is a code sample that we use in our tests:</p>
  
  <pre><code>Configuration config = HBaseConfiguration.create();
  config.clear();
  config.setInt("timeout", 12000);
  config.set("zookeeper.znode.parent", "/hbase");
  config.set("hbase.zookeeper.quorum", "127.0.0.1");
  config.set("hbase.zookeeper.property.clientPort", "2181");
  config.set("hbase.master", "127.0.0.1:60000");
  
  final Configuration configuration = HBaseConfiguration.create(config);
  
  JobDefinition.Buildable.dumpProperties(configuration, newArrayList("hbase.*"));
  
  HBaseAdmin.checkHBaseAvailable(config);
  </code></pre>
  
  <p>Which causes the following exception </p>
  
  <pre><code>Exception in thread "main" org.apache.hadoop.hbase.MasterNotRunningException: com.google.protobuf.ServiceException: java.net.UnknownHostException: unknown host: a3e6c240af20
      at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation$StubMaker.makeStub(HConnectionManager.java:1651)
      at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation$MasterServiceStubMaker.makeStub(HConnectionManager.java:1677)
      at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.getKeepAliveMasterService(HConnectionManager.java:1885)
      at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.isMasterRunning(HConnectionManager.java:900)
      at org.apache.hadoop.hbase.client.HBaseAdmin.checkHBaseAvailable(HBaseAdmin.java:2366)
      at com.xxx.compute.hadoop.jobs.transaction.OurTest.main(OurTest.java:24)
  Caused by: com.google.protobuf.ServiceException: java.net.UnknownHostException: unknown host: a3e6c240af20
      at org.apache.hadoop.hbase.ipc.RpcClient.callBlockingMethod(RpcClient.java:1674)
      at org.apache.hadoop.hbase.ipc.RpcClient$BlockingRpcChannelImplementation.callBlockingMethod(RpcClient.java:1715)
      at org.apache.hadoop.hbase.protobuf.generated.MasterProtos$MasterService$BlockingStub.isMasterRunning(MasterProtos.java:42561)
      at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation$MasterServiceStubMaker.isMasterRunning(HConnectionManager.java:1688)
      at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation$StubMaker.makeStubNoRetries(HConnectionManager.java:1597)
      at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation$StubMaker.makeStub(HConnectionManager.java:1623)
      ... 5 more
  Caused by: java.net.UnknownHostException: unknown host: a3e6c240af20
      at org.apache.hadoop.hbase.ipc.RpcClient$Connection.&lt;init&gt;(RpcClient.java:386)
      at org.apache.hadoop.hbase.ipc.RpcClient.createConnection(RpcClient.java:352)
      at org.apache.hadoop.hbase.ipc.RpcClient.getConnection(RpcClient.java:1526)
      at org.apache.hadoop.hbase.ipc.RpcClient.call(RpcClient.java:1438)
      at org.apache.hadoop.hbase.ipc.RpcClient.callBlockingMethod(RpcClient.java:1657)
      ... 10 more
  </code></pre>
  
  <p>This is explainable. We run Windows, which requires <code>boot2docker-vm</code> virtual machine running using NAT. The Docker container of the image is running inside the <code>boot2docker-vm</code> also using NAT. However, the ports are "visible" to the host machine running tests, since Docker container exports the ports, and the <code>boot2docker-vm</code> forwards the ports the host machine. The name <code>a3e6c240af20</code> actually comes from the Docker container ID, so probably <code>a3e6c240af20</code> is a hostname for the Docker container :</p>
  
  <pre><code>CONTAINER ID        IMAGE                           COMMAND                CREATED             STATUS              PORTS                                                                                                                            NAMES
  a3e6c240af20        banno/hbase-standalone:latest   "/bin/sh -c '/opt/hb   24 minutes ago      Up 24 minutes       0.0.0.0:2181-&gt;2181/tcp, 0.0.0.0:60000-&gt;60000/tcp, 0.0.0.0:60010-&gt;60010/tcp, 0.0.0.0:60020-&gt;60020/tcp, 0.0.0.0:60030-&gt;60030/tcp   agitated_wozniak
  </code></pre>
  
  <p>I am not sure how exactly HBase communication works, but apparently it makes RPC calls to the instance. HBase Docker returns its hostname hoping that the client will call it there. But since both <code>boot2docker-vm</code> and Docker container running using NAT, the host machine does not see the Docker container.</p>
  
  <p>I tried to add <code>a3e6c240af20</code> to my hosts file:</p>
  
  <pre><code>127.0.0.1 a3e6c240af20
  </code></pre>
  
  <p>Then I get a different error, also during the RPC call, which actually does not help me much:</p>
  
  <pre><code>Exception in thread "main" org.apache.hadoop.hbase.MasterNotRunningException: com.google.protobuf.ServiceException: java.lang.NullPointerException
      at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation$StubMaker.makeStub(HConnectionManager.java:1651)
      at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation$MasterServiceStubMaker.makeStub(HConnectionManager.java:1677)
      at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.getKeepAliveMasterService(HConnectionManager.java:1885)
      at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.isMasterRunning(HConnectionManager.java:900)
      at org.apache.hadoop.hbase.client.HBaseAdmin.checkHBaseAvailable(HBaseAdmin.java:2366)
      at com.xxx.compute.hadoop.jobs.transaction.OurTest.main(OurTest.java:24)
  Caused by: com.google.protobuf.ServiceException: java.lang.NullPointerException
      at org.apache.hadoop.hbase.ipc.RpcClient.callBlockingMethod(RpcClient.java:1674)
      at org.apache.hadoop.hbase.ipc.RpcClient$BlockingRpcChannelImplementation.callBlockingMethod(RpcClient.java:1715)
      at org.apache.hadoop.hbase.protobuf.generated.MasterProtos$MasterService$BlockingStub.isMasterRunning(MasterProtos.java:42561)
      at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation$MasterServiceStubMaker.isMasterRunning(HConnectionManager.java:1688)
      at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation$StubMaker.makeStubNoRetries(HConnectionManager.java:1597)
      at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation$StubMaker.makeStub(HConnectionManager.java:1623)
      ... 5 more
  Caused by: java.lang.NullPointerException
      at org.apache.hadoop.hbase.ipc.RpcClient$Connection.writeRequest(RpcClient.java:1051)
      at org.apache.hadoop.hbase.ipc.RpcClient.call(RpcClient.java:1440)
      at org.apache.hadoop.hbase.ipc.RpcClient.callBlockingMethod(RpcClient.java:1657)
      ... 10 more
  </code></pre>
  
  <p>Does anyone have a suggestion how this can be solved?</p>