# Elasticsearch clustering on two hosts using docker-compose

**URL:** <https://discuss.elastic.co/t/elasticsearch-clustering-on-two-hosts-using-docker-compose/189480>\
**Category:** Elasticsearch\
**Created:** [July 9, 2019, 8:19am UTC](https://discuss.elastic.co/t/elasticsearch-clustering-on-two-hosts-using-docker-compose/189480 "2019-07-09T08:19:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pastechecker](https://avatars.discourse-cdn.com/v4/letter/p/0ea827/32.png) [@pastechecker](https://discuss.elastic.co/u/pastechecker)\
**Post date:** [July 9, 2019, 8:19am UTC](https://discuss.elastic.co/t/elasticsearch-clustering-on-two-hosts-using-docker-compose/189480/1 "2019-07-09T08:19:53Z")

</div>

Hello.  
I am attempting to form a cluster with 6 docker containers on two docker hosts.  
Topology below:

 ![elastic_docker](https://us1.discourse-cdn.com/elastic/original/3X/a/9/a97a8d44d65a0de901213b60d55142b3759335f8.png)

Docker-compose.yml on ELK1:

> version: '3.7'
> 
> services:  
> elk1\_es01:  
> container\_name: elk1\_es01  
> image: [docker.elastic.co/elasticsearch/elasticsearch:7.2.0](http://docker.elastic.co/elasticsearch/elasticsearch:7.2.0)  
> environment:  
> - node.name=elk1\_es01  
> - discovery.seed\_hosts=192.168.1.1:9301,elk1\_es01,elk1\_es02  
> - cluster.initial\_master\_nodes=192.168.1.1:9301,elk1\_es01  
> - "ES\_JAVA\_OPTS=-Xms31g -Xmx31g"  
> volumes: ['elk1\_data01:/usr/share/elasticsearch/data']  
> ports:  
> - 9211:9200  
> - 9311:9300
> 
> elk1\_es02:  
> container\_name: elk1\_es02  
> image: [docker.elastic.co/elasticsearch/elasticsearch:7.2.0](http://docker.elastic.co/elasticsearch/elasticsearch:7.2.0)  
> environment:  
> - node.name=elk1\_es02  
> - discovery.seed\_hosts=192.168.1.1:9301,elk1\_es01,elk1\_es02  
> - cluster.initial\_master\_nodes=192.168.1.1:9301,elk1\_es01  
> - "ES\_JAVA\_OPTS=-Xms31g -Xmx31g"  
> volumes: ['elk1\_data02:/usr/share/elasticsearch/data']  
> ports:  
> - 9212:9200  
> - 9312:9300
> 
> elk1\_es03:  
> container\_name: elk1\_es03  
> image: [docker.elastic.co/elasticsearch/elasticsearch:7.2.0](http://docker.elastic.co/elasticsearch/elasticsearch:7.2.0)  
> environment:  
> - node.name=elk1\_es03  
> - discovery.seed\_hosts=192.168.1.1:9301,elk1\_es01,elk1\_es02  
> - cluster.initial\_master\_nodes=192.168.1.1:9301,elk1\_es01  
> - "ES\_JAVA\_OPTS=-Xms31g -Xmx31g"  
> volumes: ['elk1\_data03:/usr/share/elasticsearch/data']  
> ports:  
> - 9213:9200  
> - 9313:9300
> 
> volumes: {"elk1\_data01", "elk1\_data02", "elk1\_data03"}

Docker-compose.yml on ELK2:

> version: '3.7'
> 
> services:  
> elk2\_es01:  
> container\_name: elk2\_es01  
> image: [docker.elastic.co/elasticsearch/elasticsearch:7.2.0](http://docker.elastic.co/elasticsearch/elasticsearch:7.2.0)  
> environment:  
> - node.name=elk2\_es01  
> - discovery.seed\_hosts=192.168.1.2:9311,elk2\_es01  
> - cluster.initial\_master\_nodes=192.168.1.2:9311,elk2\_es01  
> - "ES\_JAVA\_OPTS=-Xms31g -Xmx31g"  
> volumes: ['elk2\_data01:/usr/share/elasticsearch/data']  
> ports:  
> - 9201:9200  
> - 9301:9300
> 
> elk2\_es02:  
> container\_name: elk2\_es02  
> image: [docker.elastic.co/elasticsearch/elasticsearch:7.2.0](http://docker.elastic.co/elasticsearch/elasticsearch:7.2.0)  
> environment:  
> - node.name=elk2\_es02  
> - discovery.seed\_hosts=192.168.1.2:9311,elk2\_es01  
> - cluster.initial\_master\_nodes=192.168.1.2:9311,elk2\_es01  
> - "ES\_JAVA\_OPTS=-Xms31g -Xmx31g"  
> volumes: ['elk2\_data02:/usr/share/elasticsearch/data']  
> ports:  
> - 9202:9200  
> - 9302:9300
> 
> elk2\_es03:  
> container\_name: elk2\_es03  
> image: [docker.elastic.co/elasticsearch/elasticsearch:7.2.0](http://docker.elastic.co/elasticsearch/elasticsearch:7.2.0)  
> environment:  
> - node.name=elk2\_es03  
> - discovery.seed\_hosts=192.168.1.2:9311,elk2\_es01  
> - cluster.initial\_master\_nodes=192.168.1.2:9311,elk2\_es01  
> - "ES\_JAVA\_OPTS=-Xms31g -Xmx31g"  
> volumes: ['elk2\_data03:/usr/share/elasticsearch/data']  
> ports:  
> - 9203:9200  
> - 9303:9300
> 
> volumes: {"elk2\_data01", "elk2\_data02", "elk2\_data03"}

> curl [http://192.168.1.2:9211/\_cat/nodes](http://192.168.1.2:9211/_cat/nodes)  
> 172.22.0.2 4 94 18 7.70 5.35 10.72 mdi - elk1\_es03  
> 172.22.0.4 3 94 18 7.70 5.35 10.72 mdi - elk1\_es01  
> 172.22.0.3 2 94 18 7.70 5.35 10.72 mdi \* elk1\_es02
> 
> curl [http://192.168.1.1:9201/\_cat/nodes](http://192.168.1.1:9201/_cat/nodes)  
> 192.168.192.4 4 96 24 7.76 8.82 8.78 mdi \* elk2\_es01  
> 192.168.192.2 2 96 24 7.76 8.82 8.78 mdi - elk2\_es03  
> 192.168.192.3 3 96 24 7.76 8.82 8.78 mdi - elk2\_es02

I also see that they are trying to talk with the success on the data ports:

> 09:47:08.154752 IP 192.168.1.2.37574 \> 192.168.1.1.9301: Flags [S], seq 3973389975, win 29200, options [mss 1460,sackOK,TS val 3699807186 ecr 0,nop,wscale 7], length 0  
> 09:47:08.154869 IP 192.168.1.1.9301 \> 192.168.1.2.37574: Flags [S.], seq 2762589956, ack 3973389976, win 28960, options [mss 1460,sackOK,TS val 646457207 ecr 3699807186,nop,wscale 7], length 0  
> 09:47:08.154879 IP 192.168.1.1.9301 \> 192.168.1.2.37574: Flags [S.], seq 2762589956, ack 3973389976, win 28960, options [mss 1460,sackOK,TS val 646457207 ecr 3699807186,nop,wscale 7], length 0  
> 09:47:08.157545 IP 192.168.1.2.37574 \> 192.168.1.1.9301: Flags [.], ack 1, win 229, options [nop,nop,TS val 3699807188 ecr 646457207], length 0  
> 09:47:08.474771 IP 192.168.1.2.37574 \> 192.168.1.1.9301: Flags [P.], seq 1:376, ack 1, win 229, options [nop,nop,TS val 3699807508 ecr 646457207], length 375  
> 09:47:08.474967 IP 192.168.1.1.9301 \> 192.168.1.2.37574: Flags [.], ack 376, win 235, options [nop,nop,TS val 646457527 ecr 3699807508], length 0  
> 09:47:08.474975 IP 192.168.1.1.9301 \> 192.168.1.2.37574: Flags [.], ack 376, win 235, options [nop,nop,TS val 646457527 ecr 3699807508], length 0  
> 09:47:08.845807 IP 192.168.1.1.9301 \> 192.168.1.2.37574: Flags [P.], seq 1:1501, ack 376, win 235, options [nop,nop,TS val 646457898 ecr 3699807508], length 1500  
> 09:47:08.845818 IP 192.168.1.1.9301 \> 192.168.1.2.37574: Flags [P.], seq 1:1501, ack 376, win 235, options [nop,nop,TS val 646457898 ecr 3699807508], length 1500  
> 09:47:08.846216 IP 192.168.1.2.37574 \> 192.168.1.1.9301: Flags [.], ack 1501, win 252, options [nop,nop,TS val 3699807879 ecr 646457898], length 0  
> 09:47:09.476132 IP 192.168.1.2.37574 \> 192.168.1.1.9301: Flags [P.], seq 376:1678, ack 1501, win 252, options [nop,nop,TS val 3699808509 ecr 646457898], length 1302  
> 09:47:09.476249 IP 192.168.1.1.9301 \> 192.168.1.2.37574: Flags [.], ack 1678, win 258, options [nop,nop,TS val 646458528 ecr 3699808509], length 0

However, I do not see the cluster working together with elk1 and elk2. The direct connection is over fiber optic bundle addressed 192.168.1.1 \<-\> 192.168.1.2.  
I am using the default bridge network in the docker-compose.

No logs are being generated in the cluster forming between elk1 and elk2, so I must be missing some configuration.

What am I missing here?

Regards

---

<div class="post-metadata">

**Author:** ![Julien](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/julien/32/19688_2.png) [@Julien](https://discuss.elastic.co/u/Julien)\
**Post date:** [July 9, 2019, 2:08pm UTC](https://discuss.elastic.co/t/elasticsearch-clustering-on-two-hosts-using-docker-compose/189480/2 "2019-07-09T14:08:55Z")

</div>

Can you check all the host are in the same docker network by using ping from one container to the container on the other docker host:  
docker exec -it elk1\_es01 /bin/bash  
$ ping elk2\_es01

If you cannot ping then the containers are running in 2 separate docker networks, this would not be related to elasticsearch but just making sure you have the container being accessible over network

I am no expert on docker but if you use "docker-compose up -d" (I guess this is what you use because container names relates to this feature as opposed to docker swarm) to use default bridge network driver, this will just create a network valid on one docker host so it's expected you cannot connect to a separate docker network only known to another docker host. You probably need to look at docker swarm and overlay network ([https://docs.docker.com/network/overlay/](https://docs.docker.com/network/overlay/))

---

<div class="post-metadata">

**Author:** ![pastechecker](https://avatars.discourse-cdn.com/v4/letter/p/0ea827/32.png) [@pastechecker](https://discuss.elastic.co/u/pastechecker)\
**Post date:** [July 9, 2019, 4:01pm UTC](https://discuss.elastic.co/t/elasticsearch-clustering-on-two-hosts-using-docker-compose/189480/3 "2019-07-09T16:01:17Z")

</div>

For the nodes on the other network I have used not named container, but the IP.

```
root@0d8a6709b8b6 elasticsearch]# ping 192.168.1.2
PING 192.168.1.2 (192.168.1.2) 56(84) bytes of data.
64 bytes from 192.168.1.2: icmp_seq=1 ttl=63 time=0.344 ms
64 bytes from 192.168.1.2: icmp_seq=3 ttl=63 time=0.279 ms
64 bytes from 192.168.1.2: icmp_seq=5 ttl=63 time=0.330 ms
64 bytes from 192.168.1.2: icmp_seq=7 ttl=63 time=0.252 ms
64 bytes from 192.168.1.2: icmp_seq=9 ttl=63 time=0.310 ms
64 bytes from 192.168.1.2: icmp_seq=11 ttl=63 time=0.287 ms
64 bytes from 192.168.1.2: icmp_seq=13 ttl=63 time=0.264 ms
64 bytes from 192.168.1.2: icmp_seq=15 ttl=63 time=0.250 ms
64 bytes from 192.168.1.2: icmp_seq=17 ttl=63 time=0.292 ms

[root@0d8a6709b8b6 ca]# curl --cacert ca.crt -u elastic:PleaseChangeMe https://192.168.1.2:9211/_cat/nodes
192.168.48.3 5 97 14 2.49 7.18 12.96 mdi * elk1_es03
192.168.48.2 5 97 14 2.49 7.18 12.96 mdi - elk1_es02
192.168.48.4 6 97 14 2.49 7.18 12.96 mdi - elk1_es01

```

So I do have a connection over TCP and ICMP.

---

<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:** [August 6, 2019, 4:01pm UTC](https://discuss.elastic.co/t/elasticsearch-clustering-on-two-hosts-using-docker-compose/189480/4 "2019-08-06T16:01:20Z")

</div>

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