How do I forward a docker-machine port to my host port on OSX?

元气小坏坏 提交于 2019-12-03 04:24:48

问题


I’m delivering a private docker container in my company and want my colleagues to be able to access in our internal network, the problem is that my guest OS is OSX and as so I can only access my application using the 192.168.99.100:3000 default ip from docker machine.

How can I forward the docker-machine 3000 port to my host 80 port?


回答1:


At this time Docker Machine is a virtual machine running under VirtualBox in your machine, so to expose your application port you need to map your virtual machine port to your host port.

To achieve this there are two options, but before make sure your Docker Machine is stopped running:

docker-machine stop default     # see PS below if docker machine isn't default

Option 1 - Use the VirtualBox interface

  • Open VirtualBox Manager
  • Select your Docker Machine VirtualBox image (e.g.: default)
  • Open Settings -> Network -> Advanced -> Port Forward
  • Add your app name, the desired host port (e.g.: 80) and your Guest port (e.g.: 3000)

Option 2 - Use the VirtualBox command line

Just run the following command with your own parameters:

VBoxManage modifyvm "dev" --natpf1 "myapp,tcp,,80,,3000"

Final considerations

Now you can start your Docker Machine running:

docker-machine start default
eval $(docker-machine env default)

Then just start your application Docker container and test it running http://localhost/.

P.S.: Your Docker Machine name may not be default, in this case change the name accordingly.



来源:https://stackoverflow.com/questions/36286305/how-do-i-forward-a-docker-machine-port-to-my-host-port-on-osx

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