+-
macos – 如何从我的主机ping我的docker容器
我在我的mac上创建了一个ubuntu docker容器

CONTAINER ID  IMAGE   COMMAND      CREATED         STATUS         PORTS                 NAMES
5d993a622d23  ubuntu  "/bin/bash"  42 minutes ago  Up 42 minutes  0.0.0.0:123->123/tcp  kickass_ptolemy

我将端口设置为123.

我的容器IP是172.17.0.2

docker inspect 5d993a622d23 | grep IP
"LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.17.0.2",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
                    "IPAMConfig": null,
                    "IPAddress": "172.17.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,

在我的Mac上,我尝试ping我的容器,

Ping 172.17.0.2,我得到了icmp_seq 0的请求超时….

我该怎么办?所以我的本地机器可以ping我安装的容器.我是否在我的容器上缺少一些应用程序安装,这是一个普通的ubuntu系统?

最佳答案
You can’t ping or access a container interface directly with Docker for Mac.

The current best solution is to connect to your containers from
another container. At present there is no way we can provide routing
to these containers due to issues with OSX that Apple have not yet
resolved. we are tracking this requirement, but we cannot do anything
about it at present.

Docker Toolbox / VirtualBox

当通过VirtualBox或任何VirtualBox VM(如a Vagrant definition)运行Docker Toolbox,Docker Machine时,您可以设置“Host-Only Network”并通过它访问Docker VMs网络.

如果您使用的是默认的boot2docker VM,请不要更改现有界面,因为您将阻止大量Docker实用程序工作,添加新界面.

您还需要通过VM的新IP地址设置从Mac到容器网络的路由.在我的例子中,Docker网络范围是172.22.0.0/16,VM上的Host Only适配器IP是192.168.99.100.

sudo route add 172.22.0.0/16 192.168.99.100

添加permanent route to osx有点复杂

然后,您可以从Mac上获取容器

machost:~ ping -c 1 172.22.0.2
PING 172.22.0.2 (172.22.0.2): 56 data bytes
64 bytes from 172.22.0.2: icmp_seq=0 ttl=63 time=0.364 ms

--- 172.22.0.2 ping statistics ---
1 packets transmitted, 1 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 0.364/0.364/0.364/0.000 ms
点击查看更多相关文章

转载注明原文:macos – 如何从我的主机ping我的docker容器 - 乐贴网