Listen to a same port via multiple Docker containers Listen to a same port via multiple Docker containers docker docker

Listen to a same port via multiple Docker containers


KAFKA_ADVERTISED_LISTENERS need to be specified as environment variable with localhost:<port>.

By default Kafka listener will listen on 9092 port and when the producer/consumer connects to broker it will advertise the list of brokers as part of Metadata request with the host:9092.

Here you are running it in Docker, so host in broker metadata list will be reachable only within the Docker network.

To make it work, we need to make Kafka broker listen on another port, add that to advertised.listeners and also add port mapping for the new port.

ports:- "29092:29092"environment: - KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181- KAFKA_LISTENERS=INTERNAL://0.0.0.0:9092,EXTERNAL://0.0.0.0:29092- KAFKA_ADVERTISED_LISTENERS=EXTERNAL://localhost:29092,INTERNAL://kafka0:9092- KAFKA_INTER_BROKER_LISTENER_NAME=INTERNAL- KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT