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

核能气质少年 提交于 2019-12-02 17:37:59

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.

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