Home > Mobile >  Docker nodejs server running in VirtualBox guest OS (Ubuntu Server 20.04): access via host (Win10) l
Docker nodejs server running in VirtualBox guest OS (Ubuntu Server 20.04): access via host (Win10) l

Time:08-02

I'm using docker inside VirtualBox (Ubuntu Server 20.04), since I cannot use Docker Desktop in the host (Windows 10).

I have a docker nodejs container on port 3000. In my host I can access it through 192.168.56.110:3000, where 192.168.56.110 is the IP address of the VM but I need to access it through localhost:3000.

The setup is of course similar to a docker-toolbox installation (as in this question), for which I've found that the host localhost also does not work, to put it simple.

I've tried to map localhost in Windows 10, as suggested in a few answers like this one adding to C:\Windows\System32\Drivers\etc\hosts:

192.168.56.110 localhost
192.168.56.110 dev.com

But while dev.com works right away as expected, localhost doesn't.

Is there a workaround?

When I run an Angular development server in the guest, I can access it via localhost:4200 from the host but it is not completely clear to me what happens behind the scenes. Side question, how does ng serve lead to the "redirection" of localhost in the host OS?

CodePudding user response:

Run as administor a windows command prompt and enter:

netsh interface portproxy add v4tov4 listenaddress=127.0.0.1 listenport=3000 connectaddress=<replace with docker ip address> connectport=3000

To confirm, run

netsh interface portproxy show all

Good luck.

  • Related