如何让两个流浪盒子互相交谈? [英] How to get two vagrant boxes to talk to each other?

查看:26
本文介绍了如何让两个流浪盒子互相交谈?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我制作了两个流浪盒子,foobar:

$ mkdir -p foo bar$推foo;流浪者初始化 hashicorp/precise32;流浪起来;弹出$推杆;流浪者初始化 hashicorp/precise32;流浪起来;弹出

现在假设我在 foo 上启动了一个 HTTP 服务器:

$ cd foo$ vagrant ssh -c 'python -m SimpleHTTPServer 8080

我的问题是,如何让 barfoo 进行通信(例如通过 curl)?

$ cd bar$ vagrant ssh -c 'curl http://????'

解决方案

虽然问题没有说清楚,但我觉得这个老问题是在问:如果*相同*的开发机器正在运行两个 vagrant 实例,foo上运行的应用程序如何从bar`上的网址获取数据.

如果是这样,我最近在我的两个 Rails 应用程序中遇到了这个问题(每个应用程序都在同一台开发机器上的一个单独的 vagrant 实例中运行).

如果 foo 想要从 bar 获取数据,那么两部分的技巧"是:

1) 每个 Vagrant 文件都需要一行:

config.vm.network :private_network, ip: PVT_NETWORK

其中 PVT_NETWORK 是本地 IP,每个 Vagrant 文件都不同,并且可能需要在同一子网中.例如 PVT_NETWORK 可能是 192.168.50.50 (foo) 和 192.168.50.51 (bar)

2) foo 通过 PVT_NETWORK IP 地址访问 bar不是您将在网络浏览器中使用的真实"IP.

在我的 Rails 示例中,我还让每个应用程序运行在不同的端口上,所以 foo 在 localhost:3000 上,bar 在 localhost:3001 上,所以 foo 将通过

访问 bar 上的 url

http://192.168.50.51:3001/some_url

Let's say I make two vagrant boxes, foo and bar:

$ mkdir -p foo bar
$ pushd foo; vagrant init hashicorp/precise32; vagrant up; popd
$ pushd bar; vagrant init hashicorp/precise32; vagrant up; popd

Now let's say I start an HTTP server on foo:

$ cd foo
$ vagrant ssh -c 'python -m SimpleHTTPServer 8080

My question is, how can I get bar to communicate (e.g. via curl) with foo?

$ cd bar
$ vagrant ssh -c 'curl http://????'

解决方案

Although the question does not make it clear, I think this older question is asking:if the *same* development machine is running two vagrant instances, how can an app running onfoofetch data from a url onbar`.

If so, I ran into this recently for my two Rails apps(each running in a separate vagrant instance on the same development machine).

The two-part 'trick' if foo wants to fetch data from bar, is:

1) each Vagrant files needs a line:

config.vm.network :private_network, ip: PVT_NETWORK

where PVT_NETWORK is a local IP, is different for each Vagrant file, and probably needs to be in the same subnet. For example PVT_NETWORK might be 192.168.50.50 (foo) and 192.168.50.51 (bar)

2) foo accesses bar via the PVT_NETWORK IP address not the "real" IP you would use with a web browser.

In my Rails example, I also have each app running on a different port, so foo is on localhost:3000 and bar is on localhost:3001, so foo would access a url on bar via

http://192.168.50.51:3001/some_url

这篇关于如何让两个流浪盒子互相交谈?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆