No node available : Elasticsearch Transport Client can't connect to Docker container

Hi , I have issue connecting to elasticsearch in Docker container using Elasticsearch Transport Client.

If I curl to elasticsearch from terminal, it seems fine:

$ curl -XGET http://elasticsearch:9200/_nodes/http?pretty=1
    {
      "_nodes" : {
        "total" : 1,
        "successful" : 1,
        "failed" : 0
      },
      "cluster_name" : "es-cluster",
      "nodes" : {
        "NGQR55QPTyilP9kRxpT_1Q" : {
          "name" : "NGQR55Q",
          "transport_address" : "127.0.0.1:9300",
          "host" : "127.0.0.1",
          "ip" : "127.0.0.1",
          "version" : "5.5.0",
          "build_hash" : "260387d",
          "roles" : [
            "master",
            "data",
            "ingest"
          ],
          "http" : {
            "bound_address" : [
              "[::]:9200"
            ],
            "publish_address" : "172.30.254.8:9200",
            "max_content_length_in_bytes" : 104857600
          }
        }
      }
    }

And then I use transport client in Java program,

 final String clusterName = "es-cluster";
 final String hostName = "elasticsearch";
 final int port = 9200;
 final Settings settings = Settings.builder().put("cluster.name", clusterName).put("client.transport.sniff", false).build();
 TransportClient client = new PreBuiltTransportClient(settings);
 client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostName), port);

But when I tried to index a document, I got an exception saying no configured nodes are available.
What confuses me is what address(or host name) and port number I should use to connect to elastic in Docker. The ES version is 5.5.0.

Any help would be very much appreciated!!!

UPDATE
I solved the problem eventually.

By default the network ip for transport is 127.0.0.1 rather than 0.0.0.0. Because it’s only listening to 127.0.0.1 rahter than all interfaces, when accessing from outside the container, the transport is not accessible. So I set it to 0.0.0.0.

The problem following this is reseting the ip address triggers the bootstrap checks, which fail due to map counts check. Running “sysctl -w vm.max_map_count=262144” solves the problem.

Try with 9300 port

Hi thanks for your attention!

I tried 172.30.254.8:9200, 172.30.254.8:9300 and 127.0.0.1 but none of them worked. :frowning:

final int port = 9200; Wrong
final int port=9300 Correct.

final String clusterName = "es-cluster"; DIFFERENT.
The cluster.name you put in settings is esClusterName different than what you declared. Change it to your variable clusterName.

Oh my bad I typed the code here by hand and made that error. There was no variable problem in my code. Sorry about that.

Should I use 172.30.254.8 as host? Also, is 9300 available outside docker container? If I curl 172.30.254.8:9300 or 127.0.0.1, both got connection failure.

Thank you!

Can you share the logs of your node?

Make sure if port 9300 of the server where elasticsearch is installed is open to your web application hosting server.

I solved the problem eventually.

By default the network ip for transport is 127.0.0.1 rather than 0.0.0.0. Because it's only listening to 127.0.0.1 rahter than all interfaces, when accessing from outside the container, the transport is not accessible. So I set it to 0.0.0.0.

The problem following this is reseting the ip address triggers the bootstrap checks, which fail due to map counts check. Running "sysctl -w vm.max_map_count=262144" solves the problem.

1 Like

That's exactly why I asked for logs.

Glad you figured it out anyway.

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.