Kafka client unable to communicate with Kafka broker

I am spinning up a docker image for our application(.net application). Now I am making use of docker compose file to spin up kafka, zookeeper. I expect that my .Net application can identify the broker which is running on port 29092. I tried creating a common network and believed it will communicate with each other. But it did not.
This is what i tried.
I installed a telnet client on the image where I have .NET application and tried pining the machine and port which runs kafka.
So when i try telnet localhost 29092 the ping failed. But when i try telnet kafka 29092 the ping was successful. Is there a way i can let the change the way the host/port is opened from kafka:29092 to localhost:29092? I would appreciate your help in this.

Images are just the packaging and delivery item. You create and run a container based on an image.

I am not sure how telnet access is related to ping, but I assume you mean telnet can not reach the target host port.

Please share the content of the used compose file, and let us know whether you executed the telnet command on the host or inside a container.

@meyay Thank you for the reply.
Yes, you are right telnet was just used to check of the images could communicate with each other. So i pinged the kafka container from my ,Net application container(and not from the host).
I have placed the docker compose file here : GitHub - jaikishpai/docker-repo (I am not able to upload it.)

I am not sure why you keep calling containers images. An image is the delivery artifact at rest: it’s a manifest and tar archives for the image layers, no running process, no nothing, just files sitting in the file system.

Every container in a bridge network has its own localhost, and those are not the same localhost as the one from the host. So yes, if a container is supposed to communicate with another, the intended solution is to leverage dns-based service discovery: use the service names to access the other containers.

@meyay Sorry about my wrong “docker” vocabulary. I am a bit new to Docker and trying to learn myself. :slight_smile:
So do you find any reason from my docker compose file why my application running in one container not able to communicate with the kafka container? Do you have any suggestions or advice that could help me resolve my issue?

I thought your main concern is to bind kafka to localhost, which doesn’t make sense for container to container communication.


The PLAINTEXT_HOST can’t be right. It is only usefull, if the container uses the host network. It has been roughly 5 years since I used Kafka the last time, so I can’t tell how you need to configure the advertised listener correctly, but the documentation should cover it.

Thanks @meyay. I thought my issue was described clearly in my Thread. Sorry if it was not. Thanks for your effort trying to help. I tried looking into the documentation and it is as it is in my compose file.

Please share the link to the documentation.

How did you create “a common network”?

@bluepuma77 This is how i created the network

    driver: bridge

You did not specify the listener in your compose file.

I am kind of surprised the configuration in your compose file does not look (or even resemble) any of the examples from the documentation you shared.

Anyhow, since this looks like a kafka configuration problem, I will leave this for someone to respond who actually uses kafka.