Docker Community Forums

Share and learn in the Docker community.

Using localhost for to access running container

(Sanchezjjose) #1

This command below:

docker run --rm -it -p -v $(pwd):/usr/src/app sanchezjjose/my-node-app

Which I am running should apparently allow me to run my application against localhost on port 3000 locally, but instead in Kitematic I see:

'Access URL' :

In the docker terminal when running ‘docker ps’ I see:>3000/tcp

When I go to the browser, I am not able to access my application either with OR with localhost:3000.

Is there something maybe I am missing in the documentation on why this will not work? This is my current stack:

 - Mac OSX 
 - Docker 1.8.0 
 - Kitematic 0.8.1 
 - VirtualBox 5.0.0

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.

Thank you very much.

Access to Container Outside VM in Windows
(Jeff Anderson) #2


When you specify, you are binding to the docker host’s Since your docker host is in a VM, that’s different from your 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 (all interfaces). That would include the IP, and then you’d be able to access it from your host.


(Sanchezjjose) #3

Thanks for your response Jeff.

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?

(Jeff Anderson) #4

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 though: docker run -p (assuming 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 interface in the VM and redirect ports like that.

(Sanchezjjose) #5

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.

(Ajoslin103) #6

Thanks to this post:

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

server {
listen 8080;

server_name localhost; 

proxy_redirect off;                                                       
proxy_buffering off;                                                      
proxy_set_header Host $host;                                              
proxy_set_header X-Real-IP $remote_addr;                                  
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;              

location / {                                                              


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…

(Sanchezjjose) #7

Cool workaround, thanks for sharing!

(Strakha) #8

Hello, I’ve exactly the same question. I’m running docker on my Mac OS and executing my container with without specifying the IP of my host

docker run -i -p 3000:3000

ad10bbb0d7ef grafana/grafana “/” 7 minutes ago Up 7 minutes>3000/tcp grafana

It’s up and running and accessible by VM’s network IP, not my Mac IP:

Please advise, I just need it to be accessible by using my host’s ip.

(Gustavog) #9


In case someone is having the same issue, I was able to resolve by putting:

-p 3000:3000

in the docker run command, and putting:


in my rails server command. Thanks.