1

So I'm trying to make my Docker Spring Boot container wait until my Kafka container has finished created the topics for it to stream events across.

What I have tried so far is:

  • checking to see if the Kafka container has been created, this doesn't work because I'm want to wait until the topic has been created
  • Used the depends_on service configuration, but again, this waits until the service has just began to run, but I need to wait until the Kafka container has created it's topic(s).
  • Attempted to sleep for 10 seconds before the container runs, I believe this could be a solution to this problem, albeit 'hacky'. But I have failed to see the 10 sleep actually occur, this makes me believe that I am doing something wrong in the docker-compose.yml

Below you can find my docker-compose.yml:

version: '2'
services:
  zookeeper:
    image: wurstmeister/zookeeper
    ports:
      - "2181:2181"
  kafka:
    image: wurstmeister/kafka:0.10.2.0
    ports:
      - "9092:9092"
    expose:
      - "9092"
      - "2181"
    environment:
      KAFKA_ADVERTISED_HOST_NAME: localhost
      KAFKA_CREATE_TOPICS: "flight-events:1:1"
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    depends_on:
      - zookeeper
  redis:
    image: redis
    ports:
      - "6379"
    restart: always
  kafka-websocket-connector:
    command: sh -c sleep 10 
    build: ./kafka-websocket-connector
    image: andrewterra/kafka-websocket-connector
    ports:
      - "8077:8077"
    depends_on:
      - kafka
      - redis
      - zookeeper
    links:
      - kafka
      - redis

I have tried multiple different values under the command service configuration, these include:

  • ["sh", "-c", "sleep", "10"]
  • ["sleep", "10"]
  • sleep 10

Does anyone have any solutions to this problem that I am having?

terrabl
  • 743
  • 3
  • 8
  • 23
  • First of all overriding `command: sh -c sleep 10`, will mean you are only running that command and not the default command of the image – Tarun Lalwani Aug 08 '17 at 05:26
  • Possible duplicate of [Docker (Compose) client connects to Kafka too early](https://stackoverflow.com/questions/42358169/docker-compose-client-connects-to-kafka-too-early) – Taylor Hx Aug 08 '17 at 07:28
  • @TaylorHx I tried implemented the answer after I posted this question, but was getting the error `ERROR: The Compose file './docker-compose.yml' is invalid because: Unsupported config option for services.kafka: 'healthcheck' services.kafka-websocket-connector.depends_on contains an invalid type, it should be a string`. Would this be better off posted on the other question? – terrabl Aug 08 '17 at 13:31
  • 1
    @terrabl The `health-check` config option is not supported in docker-compose.yaml version 2, you'll need to change the `version` property to either `'2.1'` or `'3'`. – Taylor Hx Aug 10 '17 at 00:22

0 Answers0