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.

The Process

  1. Shut down the Windows guest machine
  2. Select the Windows guest machine in your list
  3. Go into machines settings
  4. Click network
  5. Set adapter type to NAT
  6. Click Advanced
  7. Click Port Forwarding
  8. 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
    
  9. 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.

  10. Boot up your guest machine and visit http://10.0.2.2:<port> to access the application running on your host machine.

Some Caveats

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.