如何将docker-machine端口转发到OSX上的主机端口? [英] How do I forward a docker-machine port to my host port on OSX?

查看:76
本文介绍了如何将docker-machine端口转发到OSX上的主机端口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在公司中提供一个私有Docker容器,希望我的同事能够访问我们的内部网络,问题是我的来宾操作系统是OSX,因此我只能使用192.168。访问我的应用程序99.100:3000来自docker机器的默认IP。

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.

如何将docker-machine 3000端口转发到主机80端口?

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

推荐答案

这时Docker Machine是在您计算机中VirtualBox下运行的虚拟机,因此要公开您的应用程序端口,您需要将虚拟机端口映射到您的主机端口。

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.

要实现此目的,有两种选择,但是在确保停止运行Docker Machine之前:

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

选项1-使用VirtualBox界面


  • 打开VirtualBox Manager

  • 选择您的Docker Machine VirtualBox映像(例如:默认值)

  • 打开设置->网络->高级->端口转发

  • 添加您的应用程序名称,所需的主机端口(例如:80)和您的访客端口(例如:3000)

  • 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)

选项2-使用VirtualBox命令行

只需使用自己的参数运行以下命令:

Just run the following command with your own parameters:

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

最终注意事项

现在您可以启动运行的Docker Machine了:

Now you can start your Docker Machine running:

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

然后只需启动应用程序Docker容器并在 http:// localhost /

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

PS:您的Docker机器名称可能不是默认,在这种情况下,请相应更改名称。

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

这篇关于如何将docker-machine端口转发到OSX上的主机端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆