I’m trying to set up Kafka topics for my Java Spring app using Docker Compose. I’ve tried two different Kafka images but I’m running into some issues.
First, I used wurstmeister/kafka. I got the topics running, but I can’t connect them to my app. Here’s what my docker-compose.yml looks like for that:
kafka:
image: wurstmeister/kafka:0.10.2.0
ports:
- "9092:9092"
environment:
KAFKA_ADVERTISED_HOST_NAME: localhost
KAFKA_CREATE_TOPICS: "example-topic1:1:1, example-topic2:1:1"
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
volumes:
- /var/run/docker.sock:/var/run/docker.sock
depends_on:
- zookeeper
Then I tried spotify/kafka, but I can’t get it to create topics. I’ve set the TOPICS environment variable like this:
kafka:
image: spotify/kafka
ports:
- "9092:9092"
- "2181:2181"
environment:
TOPICS: example-topic
But it’s not working. I’ve also tried putting quotes around the topic name. No luck.
Any ideas on how to get either of these setups working? I need to create Kafka topics and connect them to my Java Spring app. Thanks!