I'm new into Kafka development so I'm trying to use docker compose for starting it but I'm getting several errors related to Connection to node -1 (localhost/127.0.0.1:9092) could not be established and another Kafka. Here is my docker compose, by the way I'm using the image from confluent:
version: "3.7"
services:
zookeeper:
image: confluentinc/cp-zookeeper:latest
hostname: zookeeper
container_name: zookeeper
ports:
- "2181:2181"
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
kafka1:
image: confluentinc/cp-kafka:latest
hostname: kafka1
container_name: kafka1
depends_on:
- zookeeper
ports:
- "9092:9092"
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181'
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092
kafka2:
image: confluentinc/cp-kafka:latest
hostname: kafka2
container_name: kafka2
depends_on:
- zookeeper
ports:
- "9093:9093"
environment:
KAFKA_BROKER_ID: 2
KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181'
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9093
rest:
image: confluentinc/cp-kafka-rest:latest
hostname: rest
restart: always
depends_on:
- kafka1
- kafka2
ports:
- "8082:8082"
environment:
KAFKA_REST_LISTENERS: PLAINTEXT://localhost:8082
KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181'
KAFKA_REST_BOOTSTRAP_SERVERS: localhost:9092,localhost:9093