Reputation: 1248
I have a docker-compose file.
version: '3'
services:
zookeeper:
image: wurstmeister/zookeeper
ports:
- "2181:2181"
kafka:
image: wurstmeister/kafka
ports:
- "9092"
environment:
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092
KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_CREATE_TOPICS: "test-topic:5:2"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
I am running 2 brokers with
docker-compose scale kafka=2
Now i want to get the id of broker by running this file in docker bash of kafka
zookeeper-shell.sh localhost:2181 ls /brokers/ids
All i am getting is:-
Connecting to localhost:2181
KeeperErrorCode = ConnectionLoss for /brokers/ids
But i am able to consume and produce the message, any idea why this happening?
Upvotes: 1
Views: 1488
Reputation: 32060
You are specifying localhost
but Zookeeper is on a separate container from Kafka.
Try:
➜ docker exec -it tmp_kafka_1 zookeeper-shell.sh zookeeper:2181 ls /brokers/ids
Connecting to zookeeper:2181
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[1001]
Also note that docker-compose scale kafka=2
does not bring up the second broker - it fails during startup with
kafka_2 | [2020-04-28 14:55:19,104] ERROR [KafkaServer id=1002] Fatal error during KafkaServer startup. Prepare to shutdown (kafka.server.KafkaServer)
kafka_2 | java.lang.IllegalArgumentException: requirement failed: Configured end points localhost:9092 in advertised listeners are already registered by broker 1001
If you want an example of Docker Compose running multiple brokers check out this one.
Upvotes: 2