wurstmeister / kafka-docker

Dockerfile for Apache Kafka
http://wurstmeister.github.io/kafka-docker/
Apache License 2.0
6.92k stars 2.73k forks source link

New install, `Connection to node 1005 (/172.19.0.2:64289) could not be established. Broker may not be available` #673

Open jspc opened 3 years ago

jspc commented 3 years ago

Starting kafka via:

$ docker-compose up

Gives me the above error, after:

  1. Cloning the repo from fresh
  2. Changing the line KAFKA_ADVERTISED_HOST_NAME: 192.168.99.100 to HOSTNAME_COMMAND: "ip a | grep inet | grep -v 127 | awk '{print $$2}' | awk -F/ '{print $$1}'"

(I've pasted a patch to this issue to show precisely what I have done)

My use case is pretty simple- I have a series of containers I want to access kafka. They will attach to the network that docker-compose creates (kafka-docker_default by default), and access kafka through there, by using kafka-docker_kafka_1 as the initial broker.

Is this not possible? Is there a smarter way to accomplish what I want to accomplish? I've verified inside the container that this command correctly returns the correct IP address.

I note that if I set KAFKA_ADVERTISED_HOST_NAME to the IP 172.19.0.2 specifically (and get lucky on containers starting in the correct order, getting the correct address, and some other reason I don't follow) then the logs are clear and everything works as I want it to.

Am I misunderstanding the docs? Does HOSTNAME_COMMAND not do what i'm trying to get it to do?


diff --git a/docker-compose.yml b/docker-compose.yml
index 30ad6c4..d7e3dbe 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -10,7 +10,7 @@ services:
       - "9092"
     environment:
       DOCKER_API_VERSION: 1.22
-      KAFKA_ADVERTISED_HOST_NAME: 192.168.99.100
+      HOSTNAME_COMMAND: "ip a | grep inet | grep -v 127 | awk '{print $$2}' | awk -F/ '{print $$1}'"
       KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
     volumes:
       - /var/run/docker.sock:/var/run/docker.sock
RichardMM commented 3 years ago

did you ever find a fix for this?

dibericky commented 2 years ago

Are there any news about this?

RichardMM commented 2 years ago

use confluent's kafka image...works right out of the box. @dibericky

OneCricketeer commented 2 years ago

This image also works out of the box if the listeners are used instead of advertised host/port