Docker multi container dependency

I am fairly new to docker.

My problem is – I have a multi container application(zookeeper, kafka, producer, consumer) in which I want to run the producer and the consumer containers only after the zookeeper and kafka containers are up and running. How to edit the docker-compose file and achieve that? The kafka container needs about 15 secs to set up and create the topic to which the consumer listens to. I want to run the consumer container after the topic is created so that I already have a broker up and running. Thanks in advance.

Docker-compose file –

version: '3'

services:

  zookeeper:
    image: wurstmeister/zookeeper
    container_name: zookeeper
    ports:
      - 2181:2181

  kafka:
    image: wurstmeister/kafka
    container_name: kafka
    ports:
      - 9092:9092
    environment:
      - KAFKA_ADVERTISED_HOST_NAME=someserver
      - KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181
      - "KAFKA_CREATE_TOPICS=test:1:1"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

  consumer:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: consumer
    depends_on:
            - kafka
            - zookeeper

Dockerfile –

FROM python

RUN pip install kafka-python

RUN pip install pandas
COPY . /src

CMD ["python", "/src/consumer.py"]

Source: StackOverflow