Docker-compose with multi-node setup does not detect the second node

I'm attempting to run two ES nodes from a single server. I'm trying to get an understanding of how replica sets etc work - specific to it helping out in terms of searching.

Currently I have some data on my first ES instance. I would like to create a second node and have it act as a replica set.

This is my current docker-compose (just the relevant part)

elasticsearch:
    image: elasticsearch-img:6.3.2
    container_name: elasticsearch-container
    volumes:
      - /data/elasticsearch-1/:/usr/share/elasticsearch/data
    ports: 
      - 9200:9200 #Elasticsearch HTTP
      - 9300:9300 #Elasticsearch TCP transport
    network_mode: bridge
    restart: always
    environment:
      - node.name=es-node-1
      - cluster.name=es-cluster
      - node.master=true
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms4g -Xmx4g"
    ulimits:
      nproc: 65535
      memlock:
        soft: -1
        hard: -1

  elasticsearch2:
    image: elasticsearch-img:6.3.2
    container_name: elasticsearch-container-2
    volumes:
      - /data/elasticsearch-2/:/usr/share/elasticsearch/data
    network_mode: bridge
    restart: always
    environment:
      - node.name=es-node-2
      - cluster.name=es-cluster
      - node.master=false
      - discovery.zen.ping.unicast.hosts=elasticsearch    #for discovering the primary
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms4g -Xmx4g"
    ulimits:
      nproc: 65535
      memlock:
        soft: -1
        hard: -1

I referenced a few other help topics in this forum:


I brought up the instances. My es-node-1 comes up as usual. But my es-node-2 instance keeps erroring out stating the below.

[2019-03-25T08:03:33,759][WARN ][o.e.d.z.ZenDiscovery     ] [es-node-2] not enough master nodes discovered during pinging (found [[]], but needed [-1]), pinging again
[2019-03-25T08:03:37,769][WARN ][o.e.d.z.UnicastZenPing   ] [es-node-2] failed to resolve host [elasticsearch]
java.net.UnknownHostException: elasticsearch
	at java.net.InetAddress$CachedAddresses.get(InetAddress.java:793) ~[?:?]
	at java.net.InetAddress$NameServiceAddresses.get(InetAddress.java:879) ~[?:?]
	at java.net.InetAddress.getAllByName0(InetAddress.java:1495) ~[?:?]
	at java.net.InetAddress.getAllByName(InetAddress.java:1354) ~[?:?]
	at java.net.InetAddress.getAllByName(InetAddress.java:1288) ~[?:?]
	at org.elasticsearch.transport.TcpTransport.parse(TcpTransport.java:933) ~[elasticsearch-6.3.2.jar:6.3.2]
	at org.elasticsearch.transport.TcpTransport.addressesFromString(TcpTransport.java:888) ~[elasticsearch-6.3.2.jar:6.3.2]
	at org.elasticsearch.transport.TransportService.addressesFromString(TransportService.java:710) ~[elasticsearch-6.3.2.jar:6.3.2]
	at org.elasticsearch.discovery.zen.UnicastZenPing.lambda$resolveHostsLists$0(UnicastZenPing.java:212) ~[elasticsearch-6.3.2.jar:6.3.2]
	at java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[?:?]
	at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingRunnable.run(ThreadContext.java:626) [elasticsearch-6.3.2.jar:6.3.2]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) [?:?]
	at java.lang.Thread.run(Thread.java:844) [?:?]

Kibana also still states that it sees only my es-node-1. es-node-2 is nowhere to be found. Where am I going wrong?

Thanks.

I seem to have found my issue. It was because I did not add link to the es-node-2 container.

links:
   - elasticsearch

The above solved the issue for me.

1 Like

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