EC2 instance 1:
sudo docker run -d -p 9200:9200 -p 9300:9300 \
-e "bootstrap.memory_lock=true" \
-e "node.name=es01" \
-e "network.host=172.31.139.34" \
-e "cluster.name=docker-cluster-test" \
-e "cluster.routing.allocation.disk.threshold_enabled=false" \
-e "discovery.seed_hosts=172.31.135.140" \
-e "cluster.initial_master_nodes=es01,es02" \
-e "ES_JAVA_OPTS=-XX:UseAVX=2 -Xms1g -Xmx1g" \
--name=elasticsearch770 \
--ulimit nofile=65535:65535 \
--ulimit memlock=-1:-1 \
docker.elastic.co/elasticsearch/elasticsearch:7.7.0
EC2 Intance 2:
sudo docker run -d -p 9200:9200 -p 9300:9300 \
-e "bootstrap.memory_lock=true" \
-e "node.name=es02" \
-e "network.host=172.31.135.140" \
-e "cluster.name=docker-cluster-test" \
-e "cluster.routing.allocation.disk.threshold_enabled=false" \
-e "discovery.seed_hosts=172.31.139.34" \
-e "cluster.initial_master_nodes=es01,es02" \
-e "ES_JAVA_OPTS=-XX:UseAVX=2 -Xms1g -Xmx1g" \
--name=elasticsearch770 \
--ulimit nofile=65535:65535 \
--ulimit memlock=-1:-1 \
docker.elastic.co/elasticsearch/elasticsearch:7.7.0
I am getting issue
BindTransportException[Failed to bind to 172.31.139.34:[9300-9400]]; nested: BindException[Cannot assign requested address];
If I set don't set network.host=172.31.135.140, Its keep searching
I have fixed by adding --network=host in docker command on both EC2 instances
sudo docker run -d -p 9200:9200 -p 9300:9300 \
-e "bootstrap.memory_lock=true" \
-e "node.name=es02" \
-e "network.host=172.31.135.140" \
-e "cluster.name=docker-cluster-test" \
-e "cluster.routing.allocation.disk.threshold_enabled=false" \
-e "discovery.seed_hosts=172.31.139.34" \
-e "cluster.initial_master_nodes=es01,es02" \
-e "ES_JAVA_OPTS=-XX:UseAVX=2 -Xms1g -Xmx1g" \
--name=elasticsearch770 --network=host \
--ulimit nofile=65535:65535 \
--ulimit memlock=-1:-1 \
docker.elastic.co/elasticsearch/elasticsearch:7.7.0