Interact with kafka docker container from outside of docker host [duplicate]
In the Kafka server properties you need to set advertised.host.name
and advertised.port
to the ip/port of your running container and then it should work.
Here are my two cents, since I had a hard time figuring this one out.
My $KAFKA_HOME/config/server.properties contains the following:
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
This is creating two connections, one to be used inside docker and another to be used outside. You have to choose a new port for the latter, in my case 29092, make sure this port is exposed and mapped by docker.
I was not yet able to figure out a solution without the ${outside_host_ip} in the environment, hence I'm providing the host machine's ip as an env var.
Test:
- Enter the Kafka container and create a topic:
./kafka-topics.sh -zookeeper zookeeper:2181 --create --topic dummytopic --partitions 1 --replication-factor 1
- From outside the Kafka container do:
./kafka-console-producer.sh --broker-list 0.0.0.0:29092 --topic dummytopic
and input a message
I hope this helps others
You need to put the name of the host machine where the docker instance was deployed. Also you need to map ports from docker host machine(public) to the docker container instance(private).