kafka-docker icon indicating copy to clipboard operation
kafka-docker copied to clipboard

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

Open jspc opened this issue 3 years ago • 4 comments

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

jspc avatar Jun 30 '21 05:06 jspc

did you ever find a fix for this?

RichardMM avatar Sep 13 '21 20:09 RichardMM

Are there any news about this?

dibericky avatar Feb 03 '22 10:02 dibericky

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

RichardMM avatar Feb 03 '22 15:02 RichardMM

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

OneCricketeer avatar Mar 02 '22 21:03 OneCricketeer