title: How create kafka cluster and topics in docker-compose.yml
body: <p>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!</p>
  <pre><code>version: &quot;2&quot;
  
  services:
    kafkaserver:
      image: &quot;spotify/kafka:latest&quot;
      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: &quot;mzagar/kafka-manager-docker:1.3.3.4&quot;
      container_name: kafkamanager
      networks:
        - kafkanet
      ports:
        - 9000:9000
      links:
        - kafkaserver
      environment:
        ZK_HOSTS: &quot;kafkaserver:2181&quot;
  
  networks:
    kafkanet:
      driver: bridge
  </code></pre>