我正在尝试启动一个流浪盒,然后插入一个docker elasticsearch图像......
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# virtualbox provider for ububtu box
config.vm.provider "virtualbox" do |v|
v.memory = 1024
v.cpus = 1
end
config.vm.provision "docker"
#pull docker image from https://registry.hub.docker.com/u/library/elasticsearch/
config.vm.provision "docker" do |d|
d.pull_images "elasticsearch"
d.run "elasticsearch"
end
config.vm.box = "ubuntu/trusty64"
config.vm.network "private_network", ip: "192.168.33.150"
config.vm.synced_folder ".", "/vagrant"
end
然后我可以vagrant ssh
进入流浪者的盒子里
运行docker inspect [image id]
以获取正在运行的docker镜像的IP地址并运行此...
vagrant@vagrant-ubuntu-trusty-64:~$ curl -X GET http://172.17.0.2:9200
{
"status" : 200,
"name" : "Nocturne",
"cluster_name" : "elasticsearch",
"version" : {
"number" : "1.4.4",
"build_hash" : "c88f77ffc81301dfa9dfd81ca2232f09588bd512",
"build_timestamp" : "2015-02-19T13:05:36Z",
"build_snapshot" : false,
"lucene_version" : "4.10.3"
},
"tagline" : "You Know, for Search"
}
因此,弹性搜索运行良好。问题是172.17.0.2 ip是动态的。因此,如果我想从来宾操作系统访问elasticsearch,我需要检查docker镜像以获取它。
我可以用vagrant定义172.17.0.x的ip地址吗? 有没有更好的方法在docker图像中“发现”弹性搜索?
答案 0 :(得分:2)
我认为您希望在vagrant IP上公开elasticsearch端口。您应该能够在d.run
部分中按照以下方式执行此操作:
d.run "elasticsearch",
args: "-p '9200:9200'"
(文件是here)
然后你应该可以使用流浪的IP,例如curl 192.168.33.150:9200