Kafka Docker network_mode

时间:2016-09-07 14:36:10

标签: networking docker apache-kafka mode

我试图使用docker compose在我的Mac上运行Kafka。

这是我的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加载时,它会在找到Zookeeper后发现我收到以下错误。

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

通过删除" network_mode:" host"我能够启动并运行Kafka。每个容器的行。并将zookeeper url设置为:" zookeeper:2181"

我不清楚network_mode的作用以及阻止kafka运行的原因。我希望有人可以对此有所了解并教育我。

非常感谢

1 个答案:

答案 0 :(得分:0)

您可以代替

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

为他们提供zookeeper容器的名称,在您的情况下为zookeeper

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

这有帮助吗?