简体   繁体   English

如何连接到在vagrant guest OS中运行elasticsearch的docker box?

[英]How to connect to a docker box running elasticsearch inside a vagrant guest os?

I'm trying to start a vagrant box that in turn pulls in a docker elasticsearch image... 我正在尝试启动一个流浪盒,然后插入一个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

I can then vagrant ssh into the vagrant box, run docker inspect [image id] to get the ip address of the running docker image and run this... 然后我可以将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"
}

So elasticsearch is running fine. 所以elasticsearch运行良好。 The problem is the 172.17.0.2 ip is dynamic. 问题是172.17.0.2 ip是动态的。 So if I want to access elasticsearch from the guest OS I need to inspect the docker image to get it. 因此,如果我想从客户操作系统访问elasticsearch,我需要检查docker镜像以获取它。

Can I define the 172.17.0.x ip address with vagrant? 我可以用vagrant定义172.17.0.x的ip地址吗? Is there a better way to 'discover' elasticsearch in the docker image? 有没有更好的方法在docker图像中“发现”弹性搜索?

I think you want to expose the elasticsearch port on the vagrant IP. 我想你想在vagrant IP上公开elasticsearch端口。 You should be able to do this within the d.run section along the lines of: 您应该能够在d.run部分中执行以下操作:

d.run "elasticsearch",
  args: "-p '9200:9200'"

(documentation is here ) (文件在这里

Then you should be able to use the vagrant IP such as curl 192.168.33.150:9200 然后你应该能够使用流浪的IP,如curl 192.168.33.150:9200

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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