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

查看:13
本文介绍了如何将 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 机器停止运行之前:

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 管理器
  • 选择您的 Docker Machine VirtualBox 映像(例如:默认)
  • 打开设置 -> 网络 -> 高级 -> 端口转发
  • 添加您的应用名称、所需的主机端口(例如:80)和您的访客端口(例如:3000)

选项 2 - 使用 VirtualBox 命令行

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

Just run the following command with your own parameters:

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

最终考虑

现在你可以开始运行你的 Docker 机器了:

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

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

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

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

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