Kafka Client running on docker fails to connect to broker running on Windows Host

Our kafka setup currently comprises of the ZooKeeper, Brokers installed on a Windows Host environment (non dockerized). The Kafka client will be deployed to a linux container.
We are currently unable to connect to the Kafka brokers on the Host PC from the Kafka Client in the container, we encounter the below error
IPv4 127.0.0.1:9092 connection refused

We have tried configuring host.docker.internal to the Kafka client setup configuration, but the error still persists.

Can anyone please suggest a solution for this.

What is your advertised listener property set to? And is that address reachable from the docker container?

It’d be easier if Kafka was containerized on the same host as well, then you can use a standard Docker network bridge to connect.

The real issue to the problem, however, is that 127.0.0.1 inside a container refers to itself, not the external host machine, so you need to update the Kafka advertised.listeners to contain host.docker.internal as well as use this address in the container.