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?