Port mapping in Docker on Mac OSX installed with Docker Toolbox

时光总嘲笑我的痴心妄想 提交于 2019-12-11 13:38:45

问题


I installed Docker on a Mac using the Docker Toolbox.

I opened Docker Quickstart Terminal and ran

docker run hello-world

That works fine.

Then I tried:

docker run -d -p 8080:80 nginx

I can see that the container is added. docker log with the container id returns nothing but I think that's normal?

When I browse to localhost:8080 with chrome I don't see the nginx welcome page. I've tried running a few different containers that are supposed to serve traffic but none of them have worked. The existing github issues and SO questions all seem to be talking about things which don't exist anymore - or at least are not default on Mac OSX.


回答1:


localhost is not the host where your docker is running. You need to go to the IP address of your running docker daemon.

To find the IP address for your docker machine, run the command:

docker-machine ip default

where default is the name of your VM (as is the case I think for most installations).

If that command returned something like 192.168.99.100, then you can reach your running docker container and it's exposed port like this: 192.168.99.100:8080.



来源:https://stackoverflow.com/questions/35496273/port-mapping-in-docker-on-mac-osx-installed-with-docker-toolbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!