Kafkadocker网络模式

tez616oj  于 2021-06-07  发布在  Kafka
关注(0)|答案(1)|浏览(408)

我正在试着让Kafka在我的mac上运行docker compose。
这是我的docker-compose.yml文件:

version: '2'
services:
zookeeper:
   image:********
   network_mode: "host"
   hostname: "zookeeper"
   environment:
     - "MYID=1"
   ports:
     - "2181:2181"
     - "3888:3888"
mysql:
   image:*******
   network_mode: "host"
   hostname: "mysql"
   environment:
     - "MYSQL_ROOT_PASSWORD=password"
   ports:
     - "3306:3306"
schema-registry:
   image:********
   network_mode: "host"
   hostname: "schema-registry"
   environment:
     - "ZOOKEEPER_URL=127.0.0.1:2181"
   ports:
     - "8081:8081"
kafka:
   image:**********
   network_mode: "host"
   hostname: "kafka"
   environment:
     - "SERVICE_NAME=localhost"
     - "SERVICE_TAGS=syracuse-dev"
     - "KAFKA_ADVERTISED_HOST_NAME=localhost"
     - "KAFKA_ZOOKEEPER_CONNECT=localhost:2181"
     - "KAFKA_NUM_PARTITIONS=10"
     - "KAFKA_LISTENERS=PLAINTEXT://:9092"
     - "KAFKA_BROKER_ID=1"
     - "KAFKA_DEFAULT_REPLICATION_FACTOR=1"
   ports:
     - "9092:9092"
     - "7203:7203"

除了Kafka,一切都开始运转了。当Kafka加载它寻找zookeeper一旦发现我收到以下错误。

Found zookeeper
Error: Exception thrown by the agent : java.net.MalformedURLException: Local host name unknown: java.net.UnknownHostException: moby: moby: unknown error

我可以通过删除每个容器中的“网络模式:”主机行来启动和运行Kafka。并将zookeeper url设置为:“zookeeper:2181"
我不清楚网络模式的作用以及它为什么阻碍Kafka参选。我希望有人能给我一些启示,教育我。
非常感谢

gmol1639

gmol16391#

你可以代替

- "KAFKA_ADVERTISED_HOST_NAME=localhost"
- "KAFKA_ZOOKEEPER_CONNECT=localhost:2181"

向他们提供zookeeper容器的名称,即 zookeeper 对你来说。

- "KAFKA_ADVERTISED_HOST_NAME=zookeeper"
- "KAFKA_ZOOKEEPER_CONNECT=zookeper:2181"

有帮助吗?

相关问题