我如何从主机ping我的Docker容器 [英] How could I ping my docker container from my host

查看:1124
本文介绍了我如何从主机ping我的Docker容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Mac上创建了一个ubuntu Docker容器

I have created a ubuntu docker container on my mac

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.

I set port as 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我的容器,

On my Mac I try to ping my container,

Ping 172.17.0.2,我收到icmp_seq 0 ...的请求超时.

Ping 172.17.0.2, I got Request timeout for icmp_seq 0....

我该怎么办?因此,我的本地计算机可以ping通我安装的容器.我的容器是普通的ubuntu系统吗,我是否缺少某些应用程序安装?

What should I do? So my local machine can ping the container I installed. Did I missing some app installation on my container, which is a plain ubuntu system?

推荐答案

您可以直接使用Docker for Mac ping或访问容器接口.

当前最好的解决方案是从以下位置连接到您的容器 另一个容器.目前我们无法提供路由 由于Apple尚未出现OSX问题而将这些容器放到这些容器中 解决.我们正在跟踪此要求,但我们无能为力 关于它.

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

在运行Docker Toolbox时,通过VirtualBox或任何VirtualBox VM(例如 Vagrant定义)运行Docker Machine ),您可以设置仅限主机的网络" 并访问Docker VMs网络通过那个.

Docker Toolbox/VirtualBox

When running Docker Toolbox, Docker Machine via VirtualBox or any VirtualBox VM (like a Vagrant definition) you can setup a "Host-Only Network" and access the Docker VMs network via that.

如果使用的是default boot2docker VM,请不要更改现有接口,因为这将使大量Docker实用程序停止工作,请添加一个新接口.

If you are using the default boot2docker VM, don't change the existing interface as you will stop a whole lot of Docker utilities from working, add a new interface.

您还需要通过VM的新IP地址设置从Mac到容器网络的路由.在我的情况下,Docker网络范围为172.22.0.0/16,而VM上的仅主机适配器IP为192.168.99.100.

You will also need to setup routing from your Mac to the container networks via your VM's new IP address. In my case the Docker network range is 172.22.0.0/16 and the Host Only adapter IP on the VM is 192.168.99.100.

sudo route add 172.22.0.0/16 192.168.99.100

添加到osx的永久路由有点复杂

然后,您可以从Mac上访问容器

Then you can get to containers from your 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

这篇关于我如何从主机ping我的Docker容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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