Lincong Lincong - 11 months ago 54
Linux Question

Docker containers having trouble exposing ports to host on Mac

I was trying to expose a port from the Docker container on which my server is running to my Mac host so that my browser on the host can access it.

I could use

run -it -p <port>:<port> ...
command to expose a port. That certainly works on Linux host (I have been doing that all the time before with no problem). But never worked on my Mac. By "never worked", I mean no ports from the container side is exposed at all even though the
docker ps
commands did show the mapping like this>8080/tcp
. But nothing could be connected.

So I am wondering if there is any extra-configuration I have to do to make it happen. I am using macOS Sierra 10.12 and Docker version 1.11.1, build 5604cbe.

Any input will be appreciated! Thanks!

Answer Source

If you're using Docker Toolbox, you need to make sure to get the right Docker machine IP address.

docker run -d -p 8080:80 --name webserver nginx

Find the right IP with docker-machine ip. You might get

Then you can check it by open web browser at with out proxy.

If you're using Docker for Mac, please read this docs.