我有一个由 kafka 生产者和另一个 kafka 消费者组成的应用程序。我正在尝试将它部署在启用了多主机网络的 AWS 上的 Docker 群上。Kafka 容器由以下docker-compose.yml
文件创建:
kafka:
image: spotify/kafka
environment:
ADVERTISED_PORT: 9092
ports:
- "2181:2181"
- "9092:9092"
这就是我为不同组件运行容器的方式:
> docker-compose -f helloworld_kafka.yml --x-networking up -d
Creating network "helloworld"
...
> docker run -d --name helloworld_producer_1 --net helloworld -it elsoufy/myimage ./myexec -role producer -queue helloworld_kafka_1:9092
> docker run -d --name helloworld_consumer_1 --net helloworld -it elsoufy/myimage ./myexec -role consumer -queue helloworld_kafka_1:9092
当我检查 的/etc/hosts
时,我发现了和的helloworld_kafka_1
条目:helloworld_server_1
helloworld_consumer_1
10.0.0.2 kafka_container_id
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
10.0.0.3 helloworld_server_1
10.0.0.3 helloworld_server_1.helloworld
10.0.0.4 helloworld_consumer_1
10.0.0.4 helloworld_consumer_1.helloworld
但是当我检查后者的日志时,我意识到他们无法连接到 kafka。我看到以下内容:
> docker logs consumer_container_id
2015/11/27 16:05:52 Kafka brokers: helloworld_kafka_1:9092
2015/11/27 16:05:52 Failed to start consuming dial tcp: lookup kafka_container_id on 10.10.0.2:53: no such host
看起来容器用于解析名称10.10.0.2
的 DNS(端口)是什么时候,并且它无法访问。53
当我检查任何节点的网络时,我找不到这个地址,而且它不在helloworld
覆盖网络的范围内。如何使此 DNS 可访问?任何建议表示赞赏。