如何在编织中与docker容器进行通信?

时间:2016-04-20 09:11:12

标签: docker weave

我做了什么:

[spdocker@codebrag02 ~]$ weave launch
[spdocker@codebrag02 ~]$ weave env
export DOCKER_HOST=unix:///var/run/weave/weave.sock ORIG_DOCKER_HOST=
[spdocker@codebrag02 ~]$ eval $(weave env)

[spdocker@codebrag02 ~]$ weave run -idt --name hostA ubuntu bash
19c1caf5e6ebc6e398ddae58d253b3352847cdb78fdb58d77717450f3b156a0a
[spdocker@codebrag02 ~]$ weave run -idt --name hostB ubuntu bash
c0508959453c2d1af83ea98e7361be004fa75962897536bbb842a25382bae002
[spdocker@codebrag02 ~]$ docker exec -it 19c bash
root@hostA:/# ping hostB
PING hostB.weave.local (10.32.0.3) 56(84) bytes of data.
64 bytes from hostB.weave.local (10.32.0.3): icmp_seq=1 ttl=64 time=0.096 ms
64 bytes from hostB.weave.local (10.32.0.3): icmp_seq=2 ttl=64 time=0.061 ms
64 bytes from hostB.weave.local (10.32.0.3): icmp_seq=3 ttl=64 time=0.075 ms
^C
--- hostB.weave.local ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 0.061/0.077/0.096/0.016 ms
root@hostA:/# [spdocker@codebrag02 ~]$ 
[spdocker@codebrag02 ~]$ ping hostA.weave.local
ping: unknown host hostA.weave.local
[spdocker@codebrag02 ~]$ ping hostB.weave.local
ping: unknown host hostB.weave.local
[spdocker@codebrag02 ~]$ 

我已启动weave service,并启动2 docker container,hostA和hostB。 HostA ping成功进入hostB,但是我可以从 DOCKER HOST 中ping hostA.weave.local吗?

1 个答案:

答案 0 :(得分:1)

我认为您要求从外部主机解析容器主机名。要实现这一点,您需要将主机的DNS解析器更改为指向Weave的DNS解析器。您可以使用weave dns-args查看其地址(格式化为docker run使用,但它并不太神秘)

究竟如何修改主机的DNS解析器取决于主机的操作系统。

还有一些其他细微差别可能很重要;你能更多地谈谈你想要在更高层次上实现的目标吗?