Skip to content
Advertisement

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 0.0.0.0:32769->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!

Advertisement

Answer

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 192.168.99.100.

Then you can check it by open web browser at http://192.168.99.100:8080/ with out proxy.

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

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement