Kafka Docker - Can't produce or consume from outside of docker container Kafka Docker - Can't produce or consume from outside of docker container docker docker

Kafka Docker - Can't produce or consume from outside of docker container


This worked for me: https://stackoverflow.com/a/37655203/1839580

My summary: The ADVERTISED_HOST environment variable in the spotify/kafka container needs to change depending on whether your service is operating inside or outside the container. I an using Docker for Mac and I have my docker network set to bridged. Outside of Docker the ADVERTISED_HOST needed to be set to localhost, inside of docker, it was set to myproject_kafka_1 or whatever it ends up being on your system. To fix it, I added and entry in my MacOS host files that mapped 127.0.0.1 to myproject_kafka_1. I don't like messing with my host file, but it fixed this issue for me.

127.0.0.1   localhost127.0.0.1   myproject_kafka_1


I wasn't able to interact with Kafka from outside its container until I added the following entries to server.properties:

listener.security.protocol.map=INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXTadvertised.listeners=INSIDE://${container_ip}:9092,OUTSIDE://${outside_host_ip}:29092listeners=INSIDE://:9092,OUTSIDE://:29092inter.broker.listener.name=INSIDE

I posted a more complete answer here. Hope others won't spend as much time on this as I did.


Cleaner would be to set advertised.listeners=host-ip:port since advertised.host.name and advertised.port are deprecated in Kafka server.properties file.

If set host-ip to 0.0.0.0 it will listen requests from anywhere. But it's insecure.