I use Kafka in my Docker Compose file. My docker-compose.yaml looks like this:
version: '3.3'
services:
zookeeper:
image: wurstmeister/zookeeper
ports:
- "2181:2181"
kafka:
image: wurstmeister/kafka
ports:
- "9092:9092"
environment:
KAFKA_ADVERTISED_HOST_NAME: localhost # DEPRECATED property
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
volumes:
- /var/run/docker.sock:/var/run/docker.sock
Unfortunately, when I start and restart Kafka’s instance in Docker Compose I was constantly getting random errors. After some googling, I found that KAFKA_ADVERTISED_HOST_NAME is deprecated – please see https://github.com/wurstmeister/kafka-docker/wiki/Connectivity
So, changing my docker-compose.yaml to
version: '3.3'
services:
zookeeper:
image: wurstmeister/zookeeper
ports:
- "2181:2181"
kafka:
image: wurstmeister/kafka
ports:
- "9092:9092"
environment:
KAFKA_LISTENERS: PLAINTEXT://:9092 # This new property
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092 # And this new property
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
volumes:
- /var/run/docker.sock:/var/run/docker.sock
Helped – no more errors when starting Kafka on Docker.
[…] A while ago we’d created docker-compose.yml for Kafka and Zookeper. […]