Skip to content

Instantly share code, notes, and snippets.

@jamedge
Last active March 31, 2019 21:10
Show Gist options
  • Save jamedge/699bfceeb51f9e51fa4a36baf0f7c830 to your computer and use it in GitHub Desktop.
Save jamedge/699bfceeb51f9e51fa4a36baf0f7c830 to your computer and use it in GitHub Desktop.
[kafka: data manipulations] Data manipulations using kafka docker image #docker #shell #kafka
# Run and connect to the container
docker run --net host -it wurstmeister/kafka:0.9.0.1 bin/bash
# NOTE: if `kafka-docker` is used and container is already sterted, connecting can be done directly to started container with `docker exec -it <containerId> bash`
# navigate to kafka dir
cd $KAFKA_HOME
# listing topics
bin/kafka-topics.sh --zookeeper <zookeeper_ip>:2181 --list
# creating a kafka topic
bin/kafka-topics.sh --create --zookeeper <zookeeper_ip>:2181 --replication-factor 1 --partitions 1 --topic <topic_name>
# describing a topic
bin/kafka-topics.sh --describe --zookeeper <zookeeper_ip>:2181 --topic <topic_name>
# run producer
bin/kafka-console-producer.sh --broker-list <broker_ip>:9092 --topic <topic_name>
# run consumer (for doing it from beginnig add `--from-beginning` flag)
bin/kafka-console-consumer.sh --zookeeper <zookeeper_ip>:2181 --topic <topic_name>
# NOTE 1: for local kafka service, use:
# `zookeeper` for <zookeeper_ip>
# `localhost` for <broker_ip>
# NOTE 2: if an error happens related to container name resolution, one of ways to solve it is to add a record to `/etc/hosts`, so the machine is recognised
# e.g. line like this needs to be added
# 127.0.0.1 linuxkit-025000000001 linuxkit-025000000001
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment