# Cannot setup cluster of ES with Docker of 2 EC2 machines on 3 nodes

**URL:** <https://discuss.elastic.co/t/cannot-setup-cluster-of-es-with-docker-of-2-ec2-machines-on-3-nodes/286890>\
**Category:** Elasticsearch\
**Tags:** docker\
**Created:** [October 16, 2021, 12:41pm UTC](https://discuss.elastic.co/t/cannot-setup-cluster-of-es-with-docker-of-2-ec2-machines-on-3-nodes/286890 "2021-10-16T12:41:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![vitaly1233](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vitaly1233/32/80196_2.png) [@vitaly1233](https://discuss.elastic.co/u/vitaly1233)\
**Post date:** [October 16, 2021, 12:41pm UTC](https://discuss.elastic.co/t/cannot-setup-cluster-of-es-with-docker-of-2-ec2-machines-on-3-nodes/286890/1 "2021-10-16T12:41:14Z")

</div>

Im trying to setup 3 nodes on 2 machines as the following configuration.

following the doc - [Install Elasticsearch with Docker | Elasticsearch Guide [7.15] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html)  
(run this script on each machine)

```auto
services:
  es01:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.10.1
    container_name: es01
    environment:
      - node.name=es01
      - network.publish_host=10.2.0.38
      - cluster.name=my-cluster
      - discovery.seed_hosts=es02,es03
      - cluster.initial_master_nodes=es01,es02,es03
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - network.host=0.0.0.0
      - network.bind_host=0.0.0.0
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - vit01:/usr/share/elasticsearch/data
    ports:
      - 9200:9200
      - 9300:9300
    networks:
      - elastic
  es02:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.10.1
    container_name: es02
    environment:
      - node.name=es02
      - network.publish_host=10.2.0.38
      - cluster.name=my-cluster
      - discovery.seed_hosts=es01,es03
      - cluster.initial_master_nodes=es01,es02,es03
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - network.host=0.0.0.0
      - network.bind_host=0.0.0.0
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - vit02:/usr/share/elasticsearch/data
    networks:
      - elastic
  es03:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.10.1
    container_name: es03
    environment:
      - node.name=es03
      - network.publish_host=10.2.0.243
      - cluster.name=my-cluster
      - discovery.seed_hosts=es01,es02
      - cluster.initial_master_nodes=es01,es02,es03
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - network.host=0.0.0.0
      - network.bind_host=0.0.0.0
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - vit03:/usr/share/elasticsearch/data
    networks:
      - elastic

volumes:
  vit01:
    external: true
  vit02:
    external: true
  vit03:
    external: true

networks:
  elastic:
    driver: bridge

```

The error I got on both machines

```auto
es01 | {"type": "server", "timestamp": "2021-10-16T12:35:38,508Z", "level": "WARN", "component": "o.e.d.HandshakingTransportAddressConnector", "cluster.name": "bigid-elasticsearch-cluster", "node.name": "es01", "message": "[connectToRemoteMasterNode[172.24.0.2:9300]] completed handshake with [{es02}{1LkU4MjdQwa2j-hw9IaVlA}{Y6V0srCoTsqehcNbdy8F_g}{10.2.0.38}{10.2.0.38:9300}{cdhilmrstw}{ml.machine_memory=66548318208, ml.max_open_jobs=20, xpack.installed=true, transform.node=true}] but followup connection failed", 
es01 | "stacktrace": ["org.elasticsearch.transport.ConnectTransportException: [es02][10.2.0.38:9300] connect_exception",
es01 | "at org.elasticsearch.transport.TcpTransport$ChannelsConnectedListener.onFailure(TcpTransport.java:978) ~[elasticsearch-7.10.1.jar:7.10.1]",
es01 | "at org.elasticsearch.action.ActionListener.lambda$toBiConsumer$2(ActionListener.java:198) ~[elasticsearch-7.10.1.jar:7.10.1]",
es01 | "at org.elasticsearch.common.concurrent.CompletableContext.lambda$addListener$0(CompletableContext.java:42) ~[elasticsearch-core-7.10.1.jar:7.10.1]",
es01 | "at java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:859) ~[?:?]",
es01 | "at java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:837) ~[?:?]",
es01 | "at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:506) ~[?:?]",
es01 | "at java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:2152) ~[?:?]",
es01 | "at org.elasticsearch.common.concurrent.CompletableContext.completeExceptionally(CompletableContext.java:57) ~[elasticsearch-core-7.10.1.jar:7.10.1]",
es01 | "at org.elasticsearch.transport.netty4.Netty4TcpChannel.lambda$addListener$0(Netty4TcpChannel.java:68) ~[?:?]",
es01 | "at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:577) ~[?:?]",
es01 | "at io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:570) ~[?:?]",
es01 | "at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:549) ~[?:?]",
es01 | "at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:490) ~[?:?]",
es01 | "at io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:615) ~[?:?]",
es01 | "at io.netty.util.concurrent.DefaultPromise.setFailure0(DefaultPromise.java:608) ~[?:?]",
es01 | "at io.netty.util.concurrent.DefaultPromise.tryFailure(DefaultPromise.java:117) ~[?:?]",
es01 | "at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.fulfillConnectPromise(AbstractNioChannel.java:321) ~[?:?]",
es01 | "at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:337) ~[?:?]",
es01 | "at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:702) ~[?:?]",
es01 | "at io.netty.channel.nio.NioEventLoop.processSelectedKeysPlain(NioEventLoop.java:615) ~[?:?]",
es01 | "at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:578) ~[?:?]",
es01 | "at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493) ~[?:?]",
es01 | "at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989) ~[?:?]",
es01 | "at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[?:?]",
es01 | "at java.lang.Thread.run(Thread.java:832) [?:?]",
es01 | "Caused by: io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: 10.2.0.38/10.2.0.38:9300",

```

- TCP port 9300 is opened on both machines I can enter from by:  
telnet 10.2.0.243 9300 and vice versa.

What I'm missing ?

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [October 16, 2021, 2:25pm UTC](https://discuss.elastic.co/t/cannot-setup-cluster-of-es-with-docker-of-2-ec2-machines-on-3-nodes/286890/2 "2021-10-16T14:25:13Z")

</div>

The documentation you linked is for when you run the 3 nodes in the same host with docker compose, which seems different from what you are trying to do.

Your architecture is a little confusing, can you explain how it works? Where are you running the docker-compose? What are the IP address of the instances?

Also, this config is duplicated `network.publish_host=10.2.0.38`, you can't have two different nodes listening using the same IP address and the same port, and your `es02` container does not have any port being exposed.

---

<div class="post-metadata">

**Author:** ![vitaly1233](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vitaly1233/32/80196_2.png) [@vitaly1233](https://discuss.elastic.co/u/vitaly1233)\
**Post date:** [October 16, 2021, 2:45pm UTC](https://discuss.elastic.co/t/cannot-setup-cluster-of-es-with-docker-of-2-ec2-machines-on-3-nodes/286890/3 "2021-10-16T14:45:08Z")

</div>

Thanks for reply. So basically I have 2 ec2 machines ip 10.2.0.243 and 10.2.0.38. I want using docker compose setup 3 nodes on them. 2 nodes on 1 machine and the 3rd on second. Following the doc I creates script as in my question and run in on 2 machines. Maybe I need to split the script between the machines ? (If I expose same port on multiple nodes will get port already exists)

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [October 16, 2021, 2:59pm UTC](https://discuss.elastic.co/t/cannot-setup-cluster-of-es-with-docker-of-2-ec2-machines-on-3-nodes/286890/4 "2021-10-16T14:59:09Z")

</div>

The doc assumes that everything is going to run in one machine, your architecture is completely different.

If you are running the same docker-compose in both machines you are starting 6 nodes, 3 on each ec2 instance.

I do not know much about docker, but I don't think that using the IP address of your host as the publish address of your container will work like that as the containers will run on a different network created by docker.

From the docker documentation you have this:

> Bridge networks apply to containers running on the **same** Docker daemon host. For communication among containers running on different Docker daemon hosts, you can either manage routing at the OS level, or you can use an [overlay network](https://docs.docker.com/network/overlay/).

Which basically means that your containers will only be able to connect witch containers running on the same ec2 instance.

Your issue is more related to your network architecture, you just need to make sure that your containers can talk with each other on the publish address.

Maybe the discussion in this [post](https://discuss.elastic.co/t/add-a-node-to-elastic-running-on-docker-from-another-server/285156/8) can help a little.

---

<div class="post-metadata">

**Author:** ![vitaly1233](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vitaly1233/32/80196_2.png) [@vitaly1233](https://discuss.elastic.co/u/vitaly1233)\
**Post date:** [October 16, 2021, 6:29pm UTC](https://discuss.elastic.co/t/cannot-setup-cluster-of-es-with-docker-of-2-ec2-machines-on-3-nodes/286890/5 "2021-10-16T18:29:53Z")

</div>

So except the bridge networking issue that I'll change, Do I need to split the script so on each machine will have the relevant part of nodes configuration. E.g machine 10.2.0.38 run partially script that relevant only for ec1,ec2 part, and so on.

---

<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:** [November 13, 2021, 6:30pm UTC](https://discuss.elastic.co/t/cannot-setup-cluster-of-es-with-docker-of-2-ec2-machines-on-3-nodes/286890/6 "2021-11-13T18:30:34Z")

</div>

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