我正在尝试了解 docker-compose.yml
(也显示在本文的底部)。
问题: confluent:2181
用于以下行
KAFKA_ZOOKEEPER_CONNECT: "confluent:2181"
这个
confluent
主机名是如何定义的?如果我正确理解了Docker中的主机名,则唯一的容器主机名是zookeeper
,kafka
,rest-proxy
和schema-registry
。docker-compose.yml
version: "2"
services:
zookeeper:
image: confluent/zookeeper
ports:
- "2181:2181"
environment:
zk_id: "1"
network_mode: "host"
kafka:
image: confluent/kafka
depends_on:
- zookeeper
ports:
- "9092:9092"
environment:
KAFKA_ZOOKEEPER_CONNECT: "confluent:2181"
network_mode: "host"
rest-proxy:
image: confluent/rest-proxy
depends_on:
- zookeeper
- kafka
- schema-registry
ports:
- "8082:8082"
environment:
RP_ZOOKEEPER_CONNECT: "confluent:2181"
RP_SCHEMA_REGISTRY_URL: "http://confluent:8081"
network_mode: "host"
schema-registry:
image: confluent/schema-registry
depends_on:
- kafka
- zookeeper
ports:
- "8081:8081"
environment:
SR_KAFKASTORE_CONNECTION_URL: "confluent:2181"
network_mode: "host"
最佳答案
你是对的。根据docker-compose.yml
,所定义的服务将仅针对zookeeper
,kafka
,rest-proxy
和schema-registry
提供DNS解析,而不提供confluent
。
但是,如果您使用take a look at the documenttion from confluentinc,则要求您修改主机中的主机文件:
Edit your hosts file and add a host entry for the docker machine.
192.168.99.100 confluent
这就是为什么您可以使用
confluent
并获得名称解析的原因。它与docker或compose无关。附注:请注意您使用的图像已弃用according to their documentation
关于docker - 在docker-compose.yml中了解容器的主机名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53581126/