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

I used docker-compose build a es cluster and reference official documents。 link:Install Elasticsearch with Docker | Elasticsearch Guide [8.11] | Elastic
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
https://cloud.githubusercontent.com/assets/20079928/23781270/0dba057c-0587-11e7-944f-2897be43b6dd.png

visit http://local:9200/_cat/indices?v
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}{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 !

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

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