Skip to content

Instantly share code, notes, and snippets.

@jayeshcp
Last active June 20, 2021 00:41
Show Gist options
  • Save jayeshcp/5456d8df439cc71aec1a2c8fc6e4b05d to your computer and use it in GitHub Desktop.
Save jayeshcp/5456d8df439cc71aec1a2c8fc6e4b05d to your computer and use it in GitHub Desktop.
Kafka - Docker Compose

Kafka - Docker Compose

Run docker container in shell

docker exec -it <container id> /bin/sh

Kafka Home

cd /usr/bin

Create new topic

./kafka-topics --zookeeper zookeeper:2181 --create --topic test-topic --partitions 1 --replication-factor 1

List available topics

./kafka-topics --zookeeper zookeeper:2181 --list

Post message to a topic

./kafka-console-producer --broker-list localhost:9092 --topic test-topic

Consume message from a topic

./kafka-console-consumer --bootstrap-server localhost:9092 --topic test-topic --from-beginning
version: '3'
services:
zookeeper:
image: zookeeper:3.4.9
hostname: zookeeper
ports:
- "2181:2181"
environment:
ZOO_MY_ID: 1
ZOO_PORT: 2181
ZOO_SERVERS: server.1=zookeeper:2888:3888
volumes:
- ./data/zookeeper/data:/data
- ./data/zookeeper/datalog:/datalog
kafka2:
image: confluentinc/cp-kafka:5.3.0
hostname: kafka2
ports:
- "9092:9092"
environment:
KAFKA_ADVERTISED_LISTENERS: LISTENER_DOCKER_INTERNAL://kafka2:19092,LISTENER_DOCKER_EXTERNAL://${DOCKER_HOST_IP:-127.0.0.1}:9092
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: LISTENER_DOCKER_INTERNAL:PLAINTEXT,LISTENER_DOCKER_EXTERNAL:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME: LISTENER_DOCKER_INTERNAL
KAFKA_ZOOKEEPER_CONNECT: "zookeeper:2181"
KAFKA_BROKER_ID: 2
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
volumes:
- ./data/kafka2/data:/var/lib/kafka/data
depends_on:
- zookeeper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment