Friday, November 7, 2014

Let someone connect to your Vagrant VM over http (Port Forwarding)

One of our architects here recently set up Vagrant images that allowed us all to have dev environments that were a good replica of our staging and production environments, and all started out the same.

So, I set up my Vagrant machine, got everything running, made some changes to the code, got the new thing I wanted working, ready to get the front end guys to do their bit. I sent the url (including the vagrant ip address) and other details to my front end colleague. And he couldn't connect.

Apparently, you can't, by default, access a Vagrant machine from outside of its host machine.

I couldn't work out what I needed to google for this, but @filthynerd on Twitter came to my rescue


That first link solved my problem. Just pick a port you're not using on your local machine, add this line to your Vagrant config file, run vagrant reload, and Robert is your mother's brother:

config.vm.network "forwarded_port", guest: <vagrant port>, host: <host port>



No comments:

Post a Comment