问题描述
限时送ChatGPT账号..假设我制作了两个流浪盒子,foo
和 bar
:
$ mkdir -p foo bar$推foo;流浪者初始化 hashicorp/precise32;流浪起来;弹出$推杆;流浪者初始化 hashicorp/precise32;流浪起来;弹出
现在假设我在 foo
上启动了一个 HTTP 服务器:
$ cd foo$ vagrant ssh -c 'python -m SimpleHTTPServer 8080
我的问题是,如何让 bar
与 foo
进行通信(例如通过 curl
)?
$ cd bar$ vagrant ssh -c 'curl http://????'
解决方案 虽然问题没有说清楚,但我觉得这个老问题是在问:如果*相同*的开发机器正在运行两个 vagrant 实例,
foo上运行的应用程序如何从
bar`上的网址获取数据.
如果是这样,我最近在我的两个 Rails 应用程序中遇到了这个问题(每个应用程序都在同一台开发机器上的一个单独的 vagrant 实例中运行).
如果 foo
想要从 bar
获取数据,那么两部分的技巧"是:
1) 每个 Vagrant 文件都需要一行:
config.vmwork :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
上的 urlhttp://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 on
foofetch data from a url on
bar`.
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.vmwork :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屋!
更多推荐
[db:关键词]
发布评论