title: How to order a Kafka startup shell script for a docker container?
body: <p>I am trying to containerize a Kafka server. A normal start-up sequence for a Kafka server is like this:</p>
  
  <pre><code>A: start Zookeeper server
  B: start Broker server
  C: create topic
  </code></pre>
  
  <p>Item <code>A</code> and <code>B</code> are long running process. And <code>C</code> need to wait for <code>B</code> to come up and running.</p>
  
  <p>So I wrote a Dockerfile, with <code>ENTRYPOINT</code> executing a shell script for the above sequence:</p>
  
  <pre><code>#!/bin/sh
  
  $KAFKA_HOME/bin/zookeeper-server-start.sh $KAFKA_HOME/config/zookeeper.properties &amp;
  $KAFKA_HOME/bin/kafka-server-start.sh $KAFKA_HOME/config/server.properties &amp;
  
  $KAFKA_HOME/bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test_topic
  </code></pre>
  
  <p>However, I encountered three problems when run the docker image built from this: </p>
  
  <ul>
  <li>Docker requires the <code>ENTRYPOINT</code> process to be long-running, while above script does not. (it exits as long as the topic-creation is done) </li>
  <li>The broker server statement (the 2nd one) is long-running process. Currently I have to put it as background process using ending <code>&amp;</code>, because otherwise the statements after it are not executed at all. (But making it background also has problem: the topic creation is executed immediately, while the broker server is not ready yet.)</li>
  <li>I could not put the broker server statement as the last long-running process, because the topic creation statement has to come after the server creation.</li>
  </ul>
  
  <p>What could be a good way to arrange this start-up sequence? </p>