简体   繁体   中英

Docker access elasticsearch endpoint from host

I'm running a docker image using the following command:

 docker run -P elasticsearch:2.2

I am able to access the http endpoint that runs on port 9200 from the host, however I'm unclear on how I can set the publish_address so that it doesn't keep changing. I attempted to modify the elasticsearch.yml and set the network.publish property to the ip address assigned to docker0 and eth0 as well as lo and even though it confirms the binding in the output on startup, curling to the address gives me a connection refused.

The following elasticsearch:2.2 expose some ports 9200 and 9300. Well known ports when you use Elasticsearch. Docker recommand to use the common, traditional port for your application which is what elasticsearch:2.2 did. Don't modify the internal elasticsearch.yml; Let it as it is :)

The only thing to do is to map the image internal ports to ports from your host by using -p (lower case) option instead of -P (upper case)

Use it like this :

docker run -p 9200:9200/tcp -p 9300:9300/tcp elasticsearch:2.2

Doing so you tell docker to not use a random port but to use those that you map to the internal ports by using -p option.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM