There may be situations where you need to acccess a host machine’s application on a guest VM instance. The one situation that I ran into where I needed to do this was when I needed to test a bug that was occuring in Chrome, but only on Windows.
I develop on a mac, and was not able to deploy a branch to a QA server to test the change with a tool like BrowserStack.
I tried chasing down a few answers on StackOverflow, Quora, Google, Microsoft and even VirtualBox and was unable to find anything that was working in December of 2019.
For some background, I got this working using the Microsoft provided Windows 10 VM instance that is downloadable here.
- Shut down the Windows guest machine
- Select the Windows guest machine in your list
- Go into machines settings
- Click network
- Set adapter type to
- Click Advanced
- Click Port Forwarding
Add a forward from your host machine’s IP @ a specific port to your NAT adapter’s IP at the identical port:
Host IP: 10.31.17.16 Host Port: 3000 Guest IP: 10.0.2.2 (this is the NAT adapters bound IP) Guest Port: 3000
For every port that is running an application on your host machine, forward that port to your guest machine by using the process outlined above.
Boot up your guest machine and visit
http://10.0.2.2:<port>to access the application running on your host machine.
In my experience, if you’re going to have conflicts of port forwarding between docker containers and your VirtualBox guest machine, you’re going to have issues accessing your database. If you have a way to point your application to a QA or Staging server instead of a local docker container, you may be able to get around this caveat.
2019-12-18 00:00 +0000