所以我试图让我的Docker Spring Boot容器等到我的Kafka容器完成后创建了它的主题,以便跨越事件流。
到目前为止我尝试的是:
depends_on
服务配置,但是,这一直等到服务刚刚开始运行,但我需要等到Kafka容器创建了它的主题。docker-compose.yml
您可以在下面找到我的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
我在命令服务配置下尝试了多个不同的值,包括:
["sh", "-c", "sleep", "10"]
["sleep", "10"]
sleep 10
有没有人能解决我遇到的这个问题?