How to allow two Vagrant apps to talk to each other
An issue we ran into recently is: if the same development machine is running two Vagrant instances, how can an app running onfoo
fetch data from a url onbar
.
The two-part ‘trick’ if foo
wants to fetch data from bar
, is:
1) each app’s Vagrant file 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 our Rails example, we 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