0

I installed zookeeper and Kafka using docker with help of following link https://crunchytechbytz.wordpress.com/2018/01/28/install-apache-kafka-in-docker-container/

Now I want to publish a message on one of the topic in kafka. If I get ip of docker kafka by using the following command.

docker network inspect kafka-net

I use this ip in my application. I am able to publish message to kafka queue. How we can do the automatic mapping.

I tried one-way mapping docker container port to mapping outer port. This makes it very slow and After this consumer also not able to consume this.

Nishu Tayal
  • 20,106
  • 8
  • 49
  • 101
  • I would say that this is the answer you're looking for: https://stackoverflow.com/questions/53247553/kafka-access-inside-and-outside-docker Someone may mark this as duplicated? – Victor Calatramas Jul 05 '19 at 11:22

2 Answers2

0

If you want to access Kafka from outside of your application you must expose the port (as you said mapping to an outer-port, for example) or directly running in the network mode host --net=host.

While accessing you need to give the outer port and not the inner port.

For testing Kafka connection try:

telnet <ip_of_your_outer_machine>:<outer_port>

If you are able to telnet, then you are able to connect to it from outside.

If you choose --net=host then you should be able to access Kafka with the inner port (since in this mode you are outer port and inner port are same).

JavaTechnical
  • 8,846
  • 8
  • 61
  • 97
-1

Can you paste what is inside your kafka container? (docker inspect kafka) If there is nothing on your port mapping, you need to run docker image of kafka with -p parameter which expose port to the outside world. -p have syntax like this: "-p outside_port:inside_port" and when you want to ping kafka you will ping with outside port.

Ryukote
  • 767
  • 1
  • 10
  • 26