I also don’t have any port forwaring for port 3000 either in VirtualBox because I figured that adding the host on the run command should allow me to skip that, but I have tried with port forwarding as well and it doesn’t work either.
When you specify 127.0.0.1:3000:3000, you are binding to the docker host’s 127.0.0.1. Since your docker host is in a VM, that’s different from your 127.0.0.1 on your mac.
If you did docker run --rm -it -p 3000:3000 -v $(pwd):/usr/src/app sanchezjjose/my-node-app instead, it would bind to 0.0.0.0 (all interfaces). That would include the 192.168.99.100 IP, and then you’d be able to access it from your host.
So because I am using OSX, and the docker host is actually on a VM, there is no way for me to access my application via localhost:3000, unless I am actually port forwarding 3000 from my Mac OSX => VirtualBox VM running docker?
That is correct-- you could use virtualbox’s port forwarding feature. You would probably have to bind to the NAT interface’s address instead of 127.0.0.1 though: docker run -p 10.0.2.15:3000:3000 (assuming 10.0.2.15 is the IP of your VM’s interface attached to the virtualbox NAT network). The port forwarding feature is tied to that-- virtualbox won’t reach in to the 127.0.0.1 interface in the VM and redirect ports like that.
Thank you Jeff, appreciate your response. I have one other general question I posted here, just in case you are able to take a look, no worries if you can’t but your response was very helpful here.
I was able to use [homebrew installed] nginx to forward the ports from my containers within vbox (on os x) to my own ip address so that other machines on my network could reach my containers
I replaced the default port 8080 forward in the default nginx.conf with this
to be clear: this is a workaround, what I’d like to be able to do is tell Docker Toolbox [vbox] to get an ip address via dhcp on my network – then I’d not have to forward ports around…
I’ve found a solution. In my case am using docker-machine which in turns manages docker-machine running in Virtual Box. Simply select your Docker VM in Virtual Box, open settings > Networking > Advanced > Port forwarding.
Create a new entry and enter the details as follows:
Name: web
Protocol: TCP
Host IP: 127.0.0.1
Host Port: 80
Guest IP:
Guest Port: 80
Click OK. No need to restart. You can access your docker app on localhost:80 immediately