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 onfoofetch 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: :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 (foo) and (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