[英]Docker-machine's container contact application on Mac host
I have a Mac laptop with docker-machine's running a container with nginx and several other apps on other containers. 我有一台Mac笔记本电脑,带有docker-machine的服务器,运行带有nginx的容器以及其他容器上的其他几个应用程序。 I can contact my apps through the host vm -> through nginx container -> into app container.
我可以通过主机vm->通过nginx容器->进入应用容器来联系我的应用。
I would like to have applications contact another application running on my Mac (for debugging). 我想让应用程序与Mac上运行的另一个应用程序联系(进行调试)。 Is this possible?
这可能吗?
Yes, it is possible. 对的,这是可能的。 One simple way is use
--link
option 一种简单的方法是使用
--link
选项
docker run -ti --link mysql:mysql <Docker_image>
As recommended by @Matt, you can also build the network with latest docker. 按照@Matt的建议,您还可以使用最新的docker构建网络。
refer User-defined networks 参考用户定义的网络
Yes, you can contact services on the docker-machine VM host via TCP/IP. 是的,您可以通过TCP / IP与docker-machine VM主机上的服务联系。 The default docker virtual machines have two network interfaces attached to them.
默认docker虚拟机具有两个连接的网络接口。
The first network adapter is attached to the NAT network for internet access. 第一个网络适配器连接到NAT网络以进行Internet访问。 This provides a route to the main adapters address on your laptop, which is normally
en0
这提供了通往笔记本电脑上主适配器地址的路由,该地址通常为
en0
→ ifconfig en0 | grep "inet "
inet 192.168.10.33 netmask 0xffffff00 broadcast 192.168.10.255
You can use this address from inside your docker VM or containers to access services that are running on your mac. 您可以从Docker VM或容器内部使用此地址来访问在Mac上运行的服务。
docker@default-docker:~$ curl http://192.168.10.33:3000/time
{"time":{"now":1454987348431,"start":1454635891001}}
There is a second Host-only adapter used for docker management. 还有另一个用于docker管理的仅限主机的适配器。 The Name of the Host-only adapter in VirtualBox will map to an interface on your host.
VirtualBox中仅主机适配器的名称将映射到主机上的接口。
→ VBoxManage showvminfo default | grep "NIC 2"
NIC 2: MAC: 0800270D841E, Attachment: Host-only Interface 'vboxnet3', Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none
Your mac will have a corresponding interface 您的Mac将具有相应的界面
→ ifconfig vboxnet3
vboxnet3: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
ether 0a:00:27:00:00:03
inet 192.168.99.1 netmask 0xffffff00 broadcast 192.168.99.255
You can also use this address. 您也可以使用该地址。
docker@default-docker:~$ curl http://192.168.99.1:3000/time
{"time":{"now":1454987348590,"start":1454635891001}}
The host only adapter address is useful if your network IP changes and you need to configure something static in a container, the host adapter address' will remain consistent (unless you destroy your vm, then it might change) 如果网络IP发生更改并且您需要在容器中配置静态内容,则仅主机适配器地址很有用,“主机适配器地址”将保持一致(除非您销毁了vm,否则它可能会更改)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.