title: Docker Kafka w/ Python consumer
body: <p>I am using dockerized Kafka and written one Kafka consumer program. It works perfectly when I run Kafka in docker and application at my local machine. But when I configured the local application in docker I am facing issues. The issue may be due to a topic not created until time application started.</p>
  
  <p>docker-compose.yml</p>
  
  <pre><code>version: '3'
  services:
    zookeeper:
      image: wurstmeister/zookeeper
      ports:
        - "2181:2181"
    kafka:
      image: wurstmeister/kafka
      ports:
        - "9092:9092"
      environment:
        KAFKA_ADVERTISED_HOST_NAME: localhost
        KAFKA_CREATE_TOPICS: "test:1:1"
        KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
      volumes:
        - /var/run/docker.sock:/var/run/docker.sock
    parse-engine:
      build: .
      depends_on:
        - "kafka"
      command: python parse-engine.py
      ports:
       - "5000:5000"
  </code></pre>
  
  <p>parse-engine.py</p>
  
  <pre><code>from kafka import KafkaConsumer
  import json
  
  try:
      print('Welcome to parse engine')
      consumer = KafkaConsumer('test', bootstrap_servers='localhost:9092')
      for message in consumer:
          print(message)
  except Exception as e:
      print(e)
      # Logs the error appropriately. 
      pass
  </code></pre>
  
  <p>Error log</p>
  
  <pre><code>kafka_1         | [2018-09-21 06:27:17,400] INFO [SocketServer brokerId=1001] Started processors for 1 acceptors (kafka.network.SocketServer)
  kafka_1         | [2018-09-21 06:27:17,404] INFO Kafka version : 2.0.0 (org.apache.kafka.common.utils.AppInfoParser)
  kafka_1         | [2018-09-21 06:27:17,404] INFO Kafka commitId : 3402a8361b734732 (org.apache.kafka.common.utils.AppInfoParser)
  kafka_1         | [2018-09-21 06:27:17,431] INFO [KafkaServer id=1001] started (kafka.server.KafkaServer)
  **parse-engine_1  | Welcome to parse engine
  parse-engine_1  | NoBrokersAvailable 
  parseengine_parse-engine_1 exited with code 0**
  kafka_1         | creating topics: test:1:1
  </code></pre>
  
  <p>As I already added <strong>depends_on</strong> property in docker-compose but before starting topic application connecting so error occurred. </p>
  
  <p>I read that I can possible to add the script in the docker-compose file but I am looking for some easy way.</p>
  
  <p>Thanks for help</p>