Connecting to port 9300 running inside a Docker container

I think I have the same issue as here:

But I am not sure how to implement the fix.

Elastic (5.4.3) running in Docker, started with docker-compose.
The relevant part of the docker-compose is:

    container_name: my-elastic
        - discovery.type=single-node
        - bootstrap.memory_lock=true
        - "ES_JAVA_OPTS=-Xms1024m -Xmx3g"
            soft: -1
            hard: -1
    mem_limit: 4g
        - ../../data/elasticsearch/data:/usr/share/elasticsearch/data
        - 9200:9200
        - 9300:9300

When running a Java container as part of the docker-compose, it has no problem connecting to the elastic cluster (using port 9300 - an older connector; disclaimer: I didn't write the app, but I have to fix it).

However, when trying to run the java container on the host:

Adding transport node: localhost:9300
org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: [{#transport#-1}{MyNFks6oRdCFAS0LRj3rRQ}{localhost}{}]

I tried adding

        - network.bind_host=

to the environment, but it didn't help.

Any help would be greatly appreciated.


How do you build the TransportClient?

public static Client createTransportClient(String clusterNodes, String clusterName) throws Exception {"Creating Elasticsearch transport client");
    Settings settings = Settings.builder().put("", clusterName).put("client.transport.sniff", true).build();
    TransportClient client = new PreBuiltTransportClient(settings);

    if (StringUtils.isNotEmpty(clusterNodes)) {
        for (String clusterNode : StringUtils.split(clusterNodes, ',')) {
            String hostName = StringUtils.substringBeforeLast(clusterNode, ":");
            String port = StringUtils.substringAfterLast(clusterNode, ":");
            Assert.hasText(hostName, "[Assertion failed] missing host name in 'clusterNodes'");
            Assert.hasText(port, "[Assertion failed] missing port in 'clusterNodes'");
  "Adding transport node: " + clusterNode);
            client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostName), Integer.valueOf(port)));
    return client;

Disclaimer: this is not my code and I am rather new to Elasticsearch, so I don't know if this code is good or bad.

Thanks for your help.

What is the value for clusterName?


Hi @dadoonet,

the clusterName is elasticsearch.

Is there any hope for me to fix this please ?

Thank you.

It looks good. May be a firewall issue with port 9300 which is actually blocked?

Could you share the logs of your elasticsearch instance?

Seems like the issue is caused by client.transport.sniff set to true.

Settings settings = Settings.builder()
                            .put("", clusterName)
//                                    .put("client.transport.sniff", true)
TransportClient client = new PreBuiltTransportClient(settings);

I have commented out that line and now it works.

However, I would still like to understand why.

It seems that a lot of people complained about not being able to connect to Docker containers and also there are lots of issues with the client.transport.sniff.

But despite reading a whole bunch of issues and replies and such, I still couldn't find an explanation. Which part of what client.transport.sniff does causes the issue ?

Regardless of whether you can answer this question, thank you for your help.

I honestly don't know.

But anyway, you should not use this TransportClient anymore. It's removed in the next major version.

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