# Unable to connect to Elastic Search nodes on Docker from Java

**URL:** <https://discuss.elastic.co/t/unable-to-connect-to-elastic-search-nodes-on-docker-from-java/179061>\
**Category:** Elasticsearch\
**Created:** [April 30, 2019, 10:22am UTC](https://discuss.elastic.co/t/unable-to-connect-to-elastic-search-nodes-on-docker-from-java/179061 "2019-04-30T10:22:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Francesco\_Centrone](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/francesco_centrone/32/45311_2.png) [@Francesco\_Centrone](https://discuss.elastic.co/u/Francesco_Centrone)\
**Post date:** [April 30, 2019, 10:22am UTC](https://discuss.elastic.co/t/unable-to-connect-to-elastic-search-nodes-on-docker-from-java/179061/1 "2019-04-30T10:22:28Z")

</div>

Hello,

I am not able to connect to Elasticsearch instance runned on docker via Java.  
I use to run:  
`docker run -p 9200:9200 -p 9300:9300 -e "http.host=0.0.0.0" -e "transport.host=127.0.0.1" -e "xpack.security.enabled=false" docker.elastic.co/elasticsearch/elasticsearch:7.0.0`

No error is shown. I am able to curl localhost:9300 and I get:  
`{ "name" : "9e2b50bda737", "cluster_name" : "docker-cluster", "cluster_uuid" : "JwdhJOQlRj-41WUC7ctdKQ", "version" : { "number" : "7.0.0", "build_flavor" : "default", "build_type" : "docker", "build_hash" : "b7e28a7", "build_date" : "2019-04-05T22:55:32.697037Z", "build_snapshot" : false, "lucene_version" : "8.0.0", "minimum_wire_compatibility_version" : "6.7.0", "minimum_index_compatibility_version" : "6.0.0-beta1" }, "tagline" : "You Know, for Search" }`

But I am not able to connect from Java:  
`String clusterName = "docker-cluster"; Settings elasticsearchSettings = Settings.builder() .put("cluster.name", clusterName).build(); TransportClient client = new PreBuiltTransportClient(elasticsearchSettings); client.addTransportAddress(new TransportAddress(InetAddress.getByName("localhost"), 9300)); return client;`

Any suggestion?

thank you  
Francesco

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [April 30, 2019, 10:29am UTC](https://discuss.elastic.co/t/unable-to-connect-to-elastic-search-nodes-on-docker-from-java/179061/2 "2019-04-30T10:29:54Z")

</div>

You have transport host set to local host, while makes it inaccessible outside the container.

---

<div class="post-metadata">

**Author:** ![Francesco\_Centrone](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/francesco_centrone/32/45311_2.png) [@Francesco\_Centrone](https://discuss.elastic.co/u/Francesco_Centrone)\
**Post date:** [April 30, 2019, 10:36am UTC](https://discuss.elastic.co/t/unable-to-connect-to-elastic-search-nodes-on-docker-from-java/179061/3 "2019-04-30T10:36:35Z")

</div>

Thank you for the answer.

I am able to PUT docs in the instance via Postman also. Everything is working correctly besides from java. Could it be a firewall issue?  
EDIT: _I deactivated the firewall and it s still not working_

How should I declare the `transport.host`?

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [April 30, 2019, 10:49am UTC](https://discuss.elastic.co/t/unable-to-connect-to-elastic-search-nodes-on-docker-from-java/179061/4 "2019-04-30T10:49:30Z")

</div>

Set it to the same as `http.host`. If you are just starting out I would however recommend you switch to the high-level rest client as [the transport client is being deprecated](https://www.elastic.co/guide/en/elasticsearch/client/java-api/master/transport-client.html).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 28, 2019, 10:49am UTC](https://discuss.elastic.co/t/unable-to-connect-to-elastic-search-nodes-on-docker-from-java/179061/5 "2019-05-28T10:49:37Z")

</div>

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