This repository explains the steps to bring up a local kafka instance using docker-compose.
To use these files, you must first have the following installed:
The following steps will run a local instance of the solution using the configuration file (docker-compose.yml
):
- Clone this repository.
git clone https://github.com/chelosky/kafka-local.git
- Change directory into the root of the project.
cd kafka-local
- Build and Run the project with one of the follows commands (with docker-compose commands):
docker-compose -f docker-compose.yml up --remove-orphans --no-recreate
# if you need the project execute in the background, use the -d, --detach option
docker-compose -f docker-compose.yml up --remove-orphans --no-recreate -d
# We locate the container id with docker ps
docker ps
# We enter the command line of the kafka container using its associated id
docker exec -it [CONTAINER_ID] bash
opt/kafka_2.13-2.8.1/bin/kafka-topics.sh --create --zookeeper zookeeper:2181 --replication-factor [NUM_REPLICATION_FACTOR] --partitions [NUM_PARTITIONS] --topic [TOPIC_NAME]
opt/kafka_2.13-2.8.1/bin/kafka-topics.sh --zookeeper localhost:2181 --topic [TOPIC_NAME]
opt/kafka_2.13-2.8.1/bin/kafka-topics.sh --zookeeper localhost:2181 --delete --topic [TOPIC_NAME]
opt/kafka_2.13-2.8.1/bin/kafka-topics.sh --zookeeper localhost:2181 --alter --topic [TOPIC_NAME] --partitions [NEW_NUM_PARTITIONS]
If need to stop the execution of the solution and remove the container associated, then execute one of the follows commands(with docker-compose commands):
docker-compose down
Have a nice day.