What are your Docker resources? If Docker resources are set to unlimited on the machine, both containers will try to claim 50% of the host memory and will most likely fail.
Peraps look at the docs here that describe exactly what you are seeing
BTW those containers will each start as their own elasticsearch cluster... not as part of a single cluster..
So perhaps you should use docker compose... that is in the docs as well...
Edit: I would definitely check out the link Stephen shared for best practices. My post is just an expansion of what you have to get you up and running.
Hello, there's a couple things to try that might get both ES running. I can verify that your current docker commands won't work for what you want.
Both containers must be on the same Docker network (elastic) to communicate.
Set discovery.seed_hosts to point to the other nodes in the cluster.
Define cluster.initial_master_nodes to include all master-eligible nodes when starting a new cluster.
You can disable security features for a non-production environment by setting xpack.security.enabled=false. (Not recommended for production.)
If you prefer to keep security enabled, you need to configure SSL certificates and authentication settings as per the Elasticsearch security documentation.
-Set the ES_JAVA_OPTS environment variable to allocate less memory. Documentation here
# Create a single network for both containers
docker network create elastic
# Start the first node
docker run --name es01 --net elastic -p 9200:9200 -p 9300:9300 \
-e "node.name=es01" \
-e "cluster.name=es-docker-cluster" \
-e "discovery.seed_hosts=es02" \
-e "cluster.initial_master_nodes=es01,es02" \
-e "xpack.security.enabled=false" \
-e "ES_JAVA_OPTS=-Xms512m -Xmx512m" \
-it docker.elastic.co/elasticsearch/elasticsearch:8.2.3
# Start the second node
docker run --name es02 --net elastic -p 9201:9200 -p 9301:9300 \
-e "node.name=es02" \
-e "cluster.name=es-docker-cluster" \
-e "discovery.seed_hosts=es01" \
-e "cluster.initial_master_nodes=es01,es02" \
-e "xpack.security.enabled=false" \
-e "ES_JAVA_OPTS=-Xms512m -Xmx512m" \
-it docker.elastic.co/elasticsearch/elasticsearch:8.2.3
Then run a quick health status check of your cluster:
curl -X GET "localhost:9200/_cluster/health?pretty"
I was able to get two instances running and verified on my end. Let me know if this works!
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.