# How to connect to docker instance of elasticsearch

**URL:** <https://discuss.elastic.co/t/how-to-connect-to-docker-instance-of-elasticsearch/163394>\
**Category:** Elasticsearch\
**Created:** [January 8, 2019, 3:50pm UTC](https://discuss.elastic.co/t/how-to-connect-to-docker-instance-of-elasticsearch/163394 "2019-01-08T15:50:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![P.Satish\_Patro](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/p.satish_patro/32/40158_2.png) [@P.Satish\_Patro](https://discuss.elastic.co/u/P.Satish_Patro)\
**Post date:** [January 8, 2019, 3:50pm UTC](https://discuss.elastic.co/t/how-to-connect-to-docker-instance-of-elasticsearch/163394/1 "2019-01-08T15:50:58Z")

</div>

I have used elastic search(rest high level client) in spring boot. The local instance of my computer running fine. But, when I am trying to access the azure vm docker instance I can't able to use. I can able to get json file when hitting [ideas.cloudapp.azure.com](http://ideas.cloudapp.azure.com)(let say the host name) [ideas.cloudapp.azure.com:9200](http://ideas.cloudapp.azure.com:9200). And I am using mentioed cluster name in that json in my spring boot application  
`spring.data.elasticsearch.cluster-name = docker-cluster`

And I set the  
`spring.data.elasticsearch.cluster-nodes = ideas.cloudapp.azure.com:9300`  
In docker I have 2 port running 9200 and 9300 having same port for outside container

And I ran my program which was giving error. Then I opened my laptop's localhost instance and kept the cluster node sam and it ran but was not storing in docker instance. Later, found out it is uisng laptop's local instance, then I gave random cluster-nodes. For which also it toop laptop's local instance

And, in docker logs for es container there is no log of connected, index created, delted, or data inserted nothing.

And when I turned off local instance of laptop and ran. Still it is pointing to local instance

`Caused by: java.net.ConnectException: Timeout connecting to [localhost/127.0.0.1:9200]`

I tried debugging but when it went out of spring boot to elastic search files, it showed "source file not found". So, I can't able to debug properly

What to do?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 8, 2019, 4:40pm UTC](https://discuss.elastic.co/t/how-to-connect-to-docker-instance-of-elasticsearch/163394/2 "2019-01-08T16:40:54Z")

</div>

Not sure what you did. It's probably a Spring data elasticsearch concern or you did not open your Azure cluster to the machine where your application is running.

Did you read BTW [https://docs.spring.io/spring-data/elasticsearch/docs/3.2.0.M1/reference/html/#elasticsearch.clients.rest](https://docs.spring.io/spring-data/elasticsearch/docs/3.2.0.M1/reference/html/#elasticsearch.clients.rest) ? Are you sure that setting `spring.data.elasticsearch.cluster-nodes` sets the nodes for elasticsearch client?

You should first try to run from your machine where the app is running:

```
curl ideas.cloudapp.azure.com:9200

```

If it works well, then you need to solve the problem on spring data side.  
If it does not work, then probably your Azure 9200 port is not opened for your machine.

But please don't expose your 9200 port to internet. At least not without any security layer.

---

<div class="post-metadata">

**Author:** ![P.Satish\_Patro](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/p.satish_patro/32/40158_2.png) [@P.Satish\_Patro](https://discuss.elastic.co/u/P.Satish_Patro)\
**Post date:** [January 24, 2019, 9:20am UTC](https://discuss.elastic.co/t/how-to-connect-to-docker-instance-of-elasticsearch/163394/3 "2019-01-24T09:20:00Z")

</div>

Hi,  
By default it was connecting to localhost:9200, not to my docker based.  
After giving this in application.properties it worked

spring.elasticsearch.rest.uris = [http://ideas.cloudapp.azure.com:9200](http://ideas.cloudapp.azure.com:9200)

Before, that it can not able to point, so I think by default it was pointing to localhost

---

<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:** [February 21, 2019, 9:20am UTC](https://discuss.elastic.co/t/how-to-connect-to-docker-instance-of-elasticsearch/163394/4 "2019-02-21T09:20:02Z")

</div>

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