Run elasticsearch with docker

2019-05-25 05:20发布

问题:

I am new with elasticsearch so pardon me if my question is stupid. I am try to run it with docker. After i pulled elasticsearch image from docker hub, i ran it with command:

docker run -p 9200:9200 -p 9300:9300 --name=ES elasticsearch

But when i opened http://192.168.99.100:9200 (my docker-machine ip is 192.168.99.100) the page is not available.

I tried to change my elasticsearch.yml like below:

network.publish_host: 192.168.99.100

but it doesn't work. Anyone help me out?

Thanks.

update 1

I try pass the network.publish_host setting directly on the command line with --network.publish_host=192.168.99.100 (as @Val mentioned) but it still not working. Here the log:

$ docker run -p 9200:9200 -p 9300:9300 --name=ES elasticsearch  --network.publish_host=192.168.99.100
[2015-10-31 05:18:57,305][INFO ][node                     ] [Slipstream] version[2.0.0], pid[1], build[de54438/2015-10-22T08:09:48Z]
[2015-10-31 05:18:57,306][INFO ][node                     ] [Slipstream] initializing ...
[2015-10-31 05:18:57,445][INFO ][plugins                  ] [Slipstream] loaded [], sites []
[2015-10-31 05:18:57,655][INFO ][env                      ] [Slipstream] using [1] data paths, mounts [[/usr/share/elasticsearch/data (/dev/sda1)]], net usable_space [11.5gb], net total_space [18.1gb], spins? [possibly], types [ext4]
[2015-10-31 05:19:01,778][INFO ][node                     ] [Slipstream] initialized
[2015-10-31 05:19:01,784][INFO ][node                     ] [Slipstream] starting ...
[2015-10-31 05:19:02,072][INFO ][transport                ] [Slipstream] publish_address {192.168.99.100:9300}, bound_addresses {127.0.0.1:9300}, {[::1]:9300}
[2015-10-31 05:19:02,140][INFO ][discovery                ] [Slipstream] elasticsearch/D9frl4aqQlG_ihimJ6eY_w
[2015-10-31 05:19:05,309][INFO ][cluster.service          ] [Slipstream] new_master {Slipstream}{D9frl4aqQlG_ihimJ6eY_w}{192.168.99.100}{192.168.99.100:9300}, reason: zen-disco-join(elected_as_master, [0] joins received)
[2015-10-31 05:19:05,370][INFO ][http                     ] [Slipstream] publish_address {192.168.99.100:9200}, bound_addresses {127.0.0.1:9200}, {[::1]:9200}
[2015-10-31 05:19:05,373][INFO ][node                     ] [Slipstream] started
[2015-10-31 05:19:05,496][INFO ][gateway                  ] [Slipstream] recovered [0] indices into cluster_state

回答1:

Since the OP is using Mac, the port 9200 needs to be port forwarded (with boot2docker or with docker machine) at the VM (VirtualBox) level.

VBoxManage controlvm "boot2docker-vm" --natpf1 "tcp-port9200 ,tcp,,9200,,9200"
VBoxManage controlvm "boot2docker-vm" --natpf1 "udp-port9200 ,udp,,9200,,$9200

(controlvm if the VM is running, modifyvm is the VM is stopped)