How to visit elasticsearch in docker in another docker?

I deploy elasticsearch in docker with below command:

sudo docker run --name es1 -p 6200:9200 -p 6300:9300 -e “xpack.security.enabled=false” -e discovery.type=single-node -e “ES_JAVA_OPTS=-Xms2048m -Xmx2048m” docker.elastic.co/elasticsearch/elasticsearch:5.5.3
the host ip where the docker container run is hostip the inet addr of docker0 is 172.17.0.1 docker inpect above ES container and its ip is: 172.17.0.5

I run command in host directly(step 1):

curl -XGET ‘hostip:6200’
then I get result

I run command in another docker which is deployed on the same host with above ES(step 2):

curl -XGET ‘hostip:6200’
nothing get and the visit will timeout

I run command in another docker which is deployed on the same host with above ES(step 3):

curl -XGET ‘172.17.0.1:6200’
nothing get and the visit will timeout

I run command in another docker which is deployed on the same host with above ES(step 4):

curl -XGET ‘172.17.0.5:9200’
then I get result

I run command in another host which is diff with the host above ES deployed(step 5):

curl -XGET ‘hostip:6200’
then I get result

I run command in another docker which is deployed on the diff host with above ES(step 6):

curl -XGET ‘hostip:6200’
then I get result

so my question is: how can I visit this ES container with hostip:6200 from another container which deployed on the same host ?

–net=host is not the choose under my condition.

First of all you will want to create a custom network. Then create your ES attached to that network. Create all other containers that should talk to the ES container and access the ES container by its container name (es1 in your case).

The container ip is not reliable. Use the container name or a (self) defined network alias to address the container.