映射端口,以便您可以从OSX主机访问运行应用程序的docker [英] Map ports so you can access docker running apps from OSX host

查看:134
本文介绍了映射端口,以便您可以从OSX主机访问运行应用程序的docker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在玩Docker一段时间(在OSX上经过Vagrant),这真的很好。为了访问在Docker容器中运行的应用程序,我必须设置Vagrant使用静态IP(private_network设置)。



虽然这样做很顺利,我认为使用boot2docker的新方法比OSX中直接运行docker更轻,更方便。但是,如果我使用通常的端口转发运行docker,我得到这个错误:

  docker run -p:5672 -p:15672 mikaelhg / docker-rabbitmq 
2014/02/09 10:12:47错误:开始:无法启动容器fecd0f0225f49a889e63e9b113bff36305e9b9ab146ada6730d6cfffe9a10e0b:进程无法启动

那么如果我明确地将其映射到不同的主机端口,那么它将启动

 码头运行-p 5000:5672 -p 15000:15672 mikaelhg / docker-rabbitmq 

但是我无法在我的OSX主机中打开它。我知道这个设置不同于Vagrant,因为它不使用静态IP,而是NAT,但是我无法找到正确的文档,我可以如何从OSX主机访问我的应用程序。



任何人都可以指向正确的文档,或者给我一个示例,我需要使用什么设置来让boot2docker为我设置portforwarding?

解决方案

如果您正在使用VirtualBox,请配置端口转发,如:

 $ VBoxManage modifyvmboot2docker-vm--natpf1 udp-port5000,udp ,, 5000,,5672

阅读更多:

http://www.deadcodersociety.org/blog/forwarding-a -range-of-ports-in-virtualbox /
https:// github .com / dotcloud / docker / issues / 4007#issuecomment-34573044


I have been playing with Docker for a while (on OSX via Vagrant) which worked really nice. In order to access my apps running in the docker containers I had to setup Vagrant to use static IPs ("private_network" setup).

While this worked well I think the new approach to use boot2docker is a little lighter and more convenient as I can run docker directly in OSX. However, if I run docker with the usual port forwarding I get this error:

docker run -p :5672 -p :15672 mikaelhg/docker-rabbitmq
2014/02/09 10:12:47 Error: start: Cannot start container fecd0f0225f49a889e63e9b113bff36305e9b9ab146ada6730d6cfffe9a10e0b: Process could not be started

So then if I explicitly map this to a different host port it starts

docker run -p 5000:5672 -p 15000:15672 mikaelhg/docker-rabbitmq

However I am unable to open this in my OSX host. I am aware that this setup is different to Vagrant as it does not use static IPs but rather NAT but somehow I cannot find proper docs on how I can access my apps from the OSX host.

Can anyone point me to the right docs or give me an example what setup I need to use to get boot2docker setup the portforwarding for me?

解决方案

If you're using VirtualBox, configure port forwarding like:

$ VBoxManage modifyvm "boot2docker-vm" --natpf1 "tcp-port5000,tcp,,5000,,5672"
$ VBoxManage modifyvm "boot2docker-vm" --natpf1 "udp-port5000,udp,,5000,,5672"

Read more:
http://www.deadcodersociety.org/blog/forwarding-a-range-of-ports-in-virtualbox/ https://github.com/dotcloud/docker/issues/4007#issuecomment-34573044

这篇关于映射端口,以便您可以从OSX主机访问运行应用程序的docker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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