I am trying to deploy Apache Kafka (not Confluent Kafka) on docker containers and connect to it using kafka-python's producer and consumer api. The producer api and consumer api should be able to run outside the docker container.
The pipeline consists a zookeeper instance and 3 Kafka brokers, each residing in a separate container. The following is the docker-compose code which I use to initialize the containers.
services:
zookeeper-1:
container_name: zookeeper-1
image: zookeeper:2.7.0
build:
context: ./zookeeper
volumes:
- ./config/zookeeper-1/zookeeper.properties:/kafka/config/zookeeper.properties
kafka-1:
container_name: kafka-1
image: kafka:2.7.0
build:
context: .
volumes:
- ./config/kafka-1/server.properties:/kafka/config/server.properties
- ./data/kafka-1/:/tmp/kafka-logs/
kafka-2:
container_name: kafka-2
image: kafka:2.7.0
build:
context: .
volumes:
- ./config/kafka-2/server.properties:/kafka/config/server.properties
- ./data/kafka-2/:/tmp/kafka-logs/
kafka-3:
container_name: kafka-3
image: kafka:2.7.0
build:
context: .
volumes:
- ./config/kafka-3/server.properties:/kafka/config/server.properties
- ./data/kafka-3/:/tmp/kafka-logs/
I am able to produce and consume message using cli within docker image.
I would like to be able to access it from outside the docker containers. I know that it requires modifying the docker-compose script by adding listeners but I am new to Docker and have not been able to correctly add the listeners.
Please suggest the additions that are required so that I may access Kafka from outside the containers, on the same machine.
P.S.: I have already visited most of the kafka docker container discussions on SO, including "Connect to Kafka running in Docker","Interact with kafka docker container from outside of docker host [duplicate]", and they do not answer my query.