Unable to connect to kafka running in docker wsl2

25 Views Asked by At

I ask question here after spending hours searching for a response. I am installing docker desktop on windows with WLS2 as backend. I am unable to connect to kafka broker from intellj.

here is my docker-compose file:

version: '3.6'

services:
  zookeeper:
    image: confluentinc/cp-zookeeper
    environment:
      ZOOKEEPER_CLIENT_PORT: 2181
      ZOOKEEPER_TICK_TIME: 2000
  kafka:
    image: confluentinc/cp-kafka
    ports:
      - 9092:9092
    environment:
      KAFKA_BROKER_ID: 1
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
      KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://172.17.166.69:29092,PLAINTEXT_HOST://172.17.166.69:9092
      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
      KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1

172.17.166.69 is the ip address of wsl2. I tried also these commands: netsh interface portproxy add v4tov4 listenport=9092 listenaddress=0.0.0.0 connectport=9092 connectaddress=172.17.166.69 sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1 sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1

when I use docker exec -it container_name bash, it works. Any suggestions please ?

--- UPDATE ---

I was behind the company vpn. When I disabled the proxy it works. When I activated again the vpn, and even with using WSL-vpn-kit, I get always the same problem

0

There are 0 best solutions below