简体   繁体   English

如何从docker容器中获取mac主机IP地址?

[英]How to get mac host IP address from a docker container?

I want to access host IP address from a docker container on mac. 我想从mac上的docker容器访问主机IP地址。 I know how to do that on Linux by using the bridge0 interface. 我知道如何使用bridge0接口在Linux上执行此操作。 But docker for mac doesn't have bridge0. 但是docker for mac没有bridge0。 I tried to use the gateway 172.17.0.1 in a docker container but it doesn't work. 我试图在docker容器中使用网关172.17.0.1但它不起作用。

My docker for mac version is Docker version 1.13.0, build 49bf474 . 我的Docker version 1.13.0, build 49bf474 for mac版本是Docker version 1.13.0, build 49bf474

I looked at this link https://github.com/docker/docker/issues/22753 but it mentions to create an alias on lo0 interface which I don't want to. 我查看了这个链接https://github.com/docker/docker/issues/22753但它提到在lo0接口上创建一个我不想要的别名。 Because our project is running inside docker container and I want to provides a general way without changing anything on the host. 因为我们的项目在docker容器中运行,我想提供一种通用方法,而不需要在主机上进行任何更改。

Does anyone know how to do that in Mac? 有没有人知道如何在Mac中这样做?

From the Docker documentation : 从Docker 文档

I WANT TO CONNECT FROM A CONTAINER TO A SERVICE ON THE HOST 我想从一个集装箱连接到主机上的服务

The Mac has a changing IP address (or none if you have no network access). Mac具有更改的IP地址(如果您没有网络访问权限,则为无)。 From 17.06 onwards our recommendation is to connect to the special Mac-only DNS name docker.for.mac.localhost which will resolve to the internal IP address used by the host. 从17.06开始,我们建议连接到特殊的Mac-DNS DNS名称docker.for.mac.localhost ,它将解析为主机使用的内部IP地址。

I think you'll need to upgrade your Docker For Mac version for this to work. 我认为您需要升级Docker For Mac版才能实现此功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM