# I use docker-compose build a es cluster, how to connect it?

**URL:** <https://discuss.elastic.co/t/i-use-docker-compose-build-a-es-cluster-how-to-connect-it/78088>\
**Category:** Elasticsearch\
**Created:** [March 10, 2017, 5:40am UTC](https://discuss.elastic.co/t/i-use-docker-compose-build-a-es-cluster-how-to-connect-it/78088 "2017-03-10T05:40:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![silence](https://avatars.discourse-cdn.com/v4/letter/s/ac8455/32.png) [@silence](https://discuss.elastic.co/u/silence)\
**Post date:** [March 10, 2017, 5:40am UTC](https://discuss.elastic.co/t/i-use-docker-compose-build-a-es-cluster-how-to-connect-it/78088/1 "2017-03-10T05:40:43Z")

</div>

I used docker-compose build a es cluster and reference official documents。 link:[Install Elasticsearch with Docker | Elasticsearch Guide [8.11] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html)  
I found that each of the docker-container Ip are automatically generated, and we are in the same network, we can't connect es cluster, I would like to ask this is because I configuration wrong?

docker-compose.yml 设置：

```
version: '2'
services:
  es_balance:
    image: elasticsearch_master:2.0
    container_name: es_balance
    environment:
      - cluster.name=elasticsearch-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - node.master=false 
      - node.data=false 
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 65536
        hard: 65536
    mem_limit: 1g
    cap_add:
      - IPC_LOCK
    ports:
      - 9200:9200
    networks:
      - esnet
  es_cluster:
    image: elasticsearch_slave:2.0
    environment:
      - cluster.name=elasticsearch-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - "discovery.zen.ping.unicast.hosts=es_balance"
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 65536
        hard: 65536
    mem_limit: 1g
    cap_add:
      - IPC_LOCK
    networks:
      - esnet
networks:
  esnet:
    driver: bridge

```

visit [http://local:9200/\_cat/nodes?v](http://local:9200/_cat/nodes?v)  
[https://cloud.githubusercontent.com/assets/20079928/23781270/0dba057c-0587-11e7-944f-2897be43b6dd.png](https://cloud.githubusercontent.com/assets/20079928/23781270/0dba057c-0587-11e7-944f-2897be43b6dd.png)

visit [http://local:9200/\_cat/indices?v](http://local:9200/_cat/indices?v)  
[https://cloud.githubusercontent.com/assets/20079928/23781330/8625640c-0587-11e7-984d-52ad3b242d64.png](https://cloud.githubusercontent.com/assets/20079928/23781330/8625640c-0587-11e7-984d-52ad3b242d64.png)

JavaCode:

```
String masterHost = "172.18.0.3";

String bakHost = "172.18.0.2";

// on startup

Settings settings = Settings.builder().put("cluster.name", "elasticsearch-cluster").build();

TransportClient client = new PreBuiltTransportClient(settings)

.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(masterHost), 9300));

//.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(bakHost), 9300));

//Get API

GetResponse response = client.prepareGet("face", "summary", "AVqxwjBi2zdNu9G4HdIc").get();

Map<String, Object> source = response.getSource();

source.forEach((k,v)->System.out.println("------"+k));

```

Exception :

> Exception in thread "main" NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{BrxMkowhS9S9dZwmZcaEWg}{[bigdata4.gds.com](http://bigdata4.gds.com)}{192.168.0.204:9300}]]  
> at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:344)  
> at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:242)  
> at org.elasticsearch.client.transport.TransportProxyClient.execute(TransportProxyClient.java:59)  
> at org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:356)  
> at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:403)  
> at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:80)  
> at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:54)  
> at org.elasticsearch.action.ActionRequestBuilder.get(ActionRequestBuilder.java:62)  
> at gds.bigdata.elk.TestAPIDemo.main(TestAPIDemo.java:26)

I think this is network problem? please give me some suguestion. 3Q!  
all of docker-compose.yml use image is official image, I renamed it !

---

<div class="post-metadata">

**Author:** ![silence](https://avatars.discourse-cdn.com/v4/letter/s/ac8455/32.png) [@silence](https://discuss.elastic.co/u/silence)\
**Post date:** [March 14, 2017, 3:19am UTC](https://discuss.elastic.co/t/i-use-docker-compose-build-a-es-cluster-how-to-connect-it/78088/2 "2017-03-14T03:19:34Z")

</div>

at last, I used jest to operate es cluster，I don't know if there is any problem with this

---

<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:** [April 11, 2017, 3:19am UTC](https://discuss.elastic.co/t/i-use-docker-compose-build-a-es-cluster-how-to-connect-it/78088/3 "2017-04-11T03:19:36Z")

</div>

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