I'm having a problem running a Kafka broker in a Docker container.
I have downloaded and unpacked a tar archive of Kafka 2.12-2.4.1.
I can run Zookeeper and Kafka brokers from the command line, producing and consuming messages successfully. When I build a docker container with Zookeeper, I can run that with a Kafka broker running from the command line, again producing and consuming messages successfully. When I put the broker into a docker container, the consumers and producers can't find a broker to connect to.
I have checked to ensure that Zookeeper has a connected broker: the zookeeper "dump" command below
echo dump | nc localhost 2181
returns
SessionTracker dump: Session Sets (3)/(1): 0 expire at Thu May 28 09:53:33 GMT 2020: 0 expire at Thu May 28 09:53:36 GMT 2020: 1 expire at Thu May 28 09:53:39 GMT 2020: 0x10002dfed700008 ephemeral nodes dump: Sessions with Ephemerals (1): 0x10002dfed700008: /controller /brokers/ids/0 Connections dump: Connections Sets (2)/(2): 0 expire at Thu May 28 09:53:37 GMT 2020: 2 expire at Thu May 28 09:53:47 GMT 2020: ip: /172.18.0.1:55656 sessionId: 0x0 ip: /172.18.0.5:48474 sessionId: 0x10002dfed700008
which, to my untrained eye, looks like Zookeeper has a registered broker.
I can successfully list topics with the command
kafka-topics.sh --list --zookeeper localhost:2181
and when I run the command
netstat -plnt
I can see that I have listeners on ports 2181 and 9092, as below
tcp6 0 0 :::9092 :::* LISTEN 54661/docker-proxy tcp6 0 0 :::2181 :::* LISTEN 47872/docker-proxy
However, when I try to connect a consumer with the command
kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic aaaa
I get errors
WARN [Consumer clientId=consumer-console-consumer-8228-1, groupId=console-consumer-8228] Bootstrap broker localhost:9092 (id: -1 rack: null) disconnected (org.apache.kafka.clients.NetworkClient)
which would seem to indicate that the client can't contact the broker.
I've tried several different variations on the listeners and advertised.listeners in the broker config file, setting them to localhost and 127.0.0.1, but to no avail.
I'm sure that I'm missing something simple: can anyone help?