I am new to docker. I'd like containerize kafka and add a cluster, say MyCluster, to it and then add 4 topics, such as topic_a, topic_b, topic_c and topic_d to the cluster right after the kafka server starts. Can some please explain to me how to do that? I tried the following docker-compose.yml and I am able to launch containerized kafka server and kafka manager, but I can't create cluster/topics programmatically. Please help!
version: "2"
services:
kafkaserver:
image: "spotify/kafka:latest"
container_name: kafka
hostname: kafkaserver
networks:
- kafkanet
ports:
- 2181:2181
- 9092:9092
environment:
ADVERTISED_HOST: kafkaserver
ADVERTISED_PORT: 9092
command:
/opt/kafka_2.11-0.10.1.0/bin/kafka-topics.sh --create --zookeeper kafkaserver:2181 --replication-factor 1 --partitions 1 --topic topic_a
/opt/kafka_2.11-0.10.1.0/bin/kafka-topics.sh --create --zookeeper kafkaserver:2181 --replication-factor 1 --partitions 1 --topic topic_b
/opt/kafka_2.11-0.10.1.0/bin/kafka-topics.sh --create --zookeeper kafkaserver:2181 --replication-factor 1 --partitions 1 --topic topic_c
/opt/kafka_2.11-0.10.1.0/bin/kafka-topics.sh --create --zookeeper kafkaserver:2181 --replication-factor 1 --partitions 1 --topic topic_d
kafka_manager:
image: "mzagar/kafka-manager-docker:1.3.3.4"
container_name: kafkamanager
networks:
- kafkanet
ports:
- 9000:9000
links:
- kafkaserver
environment:
ZK_HOSTS: "kafkaserver:2181"
networks:
kafkanet:
driver: bridge