Is there a way to communicate between 2 Elasticsearch containers on the same host?

Viewed 198

I deploy 2 container of Elasticsearch by the next commands:

docker run --network host  -p 9201:9200 -p 9301:9300 -e "discovery.type=single-node"  docker.elastic.co/elasticsearch/elasticsearch:6.8.1 
docker run --network host  -p 9202:9200 -p 9302:9300 -e "discovery.type=single-node"  docker.elastic.co/elasticsearch/elasticsearch:6.8.1 

when I try to run the next command from one of the containers

curl localhost:${PORT_OF_THER_OTHER_CONTAINER}

I get the next error

curl: (7) Failed connect to localhost:PORT_OF_THER_OTHER_CONTAINER; Connection refused
1 Answers

You need to use the bridge network in both the ES container so that they can discover each other and than use the internal port in order to connect to another container using curl.

  1. Create a bridge network named as my-bridge-network

docker network create -d bridge my-bridge-network

  1. use above created my-bridge-network and custom name in docker run command as

docker run --network my-bridge --name es1 -p 9201:9200 -p 9301:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:6.8.1

Now, after going inside container one docker exec -it <container-id> /bin/bash run the curl command as curl es1:9200 which gives proper output.

{
  "name" : "vwdvbT9",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "dwMh_zK6RmO_VeeoDQXuTg",
  "version" : {
    "number" : "6.8.1",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "1fad4e1",
    "build_date" : "2019-06-18T13:16:52.517138Z",
    "build_snapshot" : false,
    "lucene_version" : "7.7.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}```

 
Related