Kafka Single Node

Goal: During development on Kafka streamings, we like to set up single node Kafka broker

Git clone the repo

$ git clone git@github.com:abulbasar/docker-examples.git
$ cd docker-example/kafka-single-node

Build the local docker image and run it using docker-compose. Do not close this terminal. If you want to run the container in background, append -d argument in the docker-compose up command.

$ docker-compose build && docker-compose up

Verify that the container is running

$ docker ps
CONTAINER ID        IMAGE                      COMMAND                  CREATED             STATUS              PORTS                                            NAMES
461557deac68        kafka-single-node_broker   "bash /start-serviceā€¦"   8 minutes ago       Up 19 seconds>2181/tcp,>9092/tcp   kafka-single-node_broker_1

Launch a new terminal with console consumer. With topic auto creation turned on by default, the topic named sample will be created by default.

$ $ docker exec -it kafka-single-node_broker_1 kafka-console-producer.sh --broker-list kafka:9092 --topic sample

Launch another terminal with producer

$ $ docker exec -it kafka-single-node_broker_1 kafka-console-consumer.sh --bootstrap-server kafka:9092 --topic sample --from-beginning

Note: bootstrap server is the name of the hostname set in the docker-compose.yml file.

Type in a few message in the producer and see those message appear in the console consumer end.