使用"container ip"连接到docker容器. [英] Connecting to docker container using "container ip"

查看:99
本文介绍了使用"container ip"连接到docker容器.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Mac上运行docker.我想使用其ip(而不是虚拟盒子机器的ip)连接到docker容器.原因是spark驱动程序向容器ip"172.17.0.2"注册了自己,并且从mac运行的客户端尝试连接到该地址.有没有办法通过IP地址为192.168.99.1.的Macbook连接到172.17.0.2.

I am running docker on mac. I would like to connect to docker container using its ip (not the ip of the virtual box machine). The reason is spark driver registers itself with container ip "172.17.0.2" and the client running from mac tries to connect to this address. Is there a way to connect to 172.17.0.2 from macbook with ip 192.168.99.1.

ravis-MacBook-Pro:datadir raviramadoss$ ifconfig | grep inet
    inet6 ::1 prefixlen 128
    inet 127.0.0.1 netmask 0xff000000
    inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
    inet6 fe80::22c9:d0ff:fec3:ab3b%en1 prefixlen 64 scopeid 0x5
    inet 172.20.10.2 netmask 0xfffffff0 broadcast 172.20.10.15
    inet6 fe80::2c59:11ff:fe77:f5a6%awdl0 prefixlen 64 scopeid 0x9
    inet6 fe80::8f9:68c0:9430:41eb%utun0 prefixlen 64 scopeid 0xb
    inet6 fdd6:aa86:393a:d244:8f9:68c0:9430:41eb prefixlen 64
    inet 192.168.99.1 netmask 0xffffff00 broadcast 192.168.99.255
    inet6 fe80::4fc0:193a:6763:2e97%utun1 prefixlen 64 scooped 0x14

虚拟盒子ip

ravis-MacBook-Pro:sbin raviramadoss$ docker-machine ip
192.168.99.100

容器

[raviramadoss@karaba logs]$ ifconfig | grep inet
          inet addr:172.17.0.2  Bcast:0.0.0.0  Mask:255.255.0.0
          inet6 addr: fe80::42:acff:fe11:2/64 Scope:Link
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host

感谢您的帮助.谢谢拉维R

Any help is appreciated. Thanks Ravi R

推荐答案

查看 Docker网络.您在Container内看到的IP是docker网络旁边的私有IP.

Look at Docker Networks. The IP you see inside the Container is the private IP iside the docker network.

访问容器以

The only (good) way to access the container to publish a port of the container and access it via VM-IP:published-container-port. Alternatively you can use the option --net=host to use the docker hosts netwok interface directly but this is not recommended.

这篇关于使用"container ip"连接到docker容器.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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