0

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

  • 1) Running one broker on the same machine is less performant than only one 2) You need to make the brokers advertise their service names 3) In order for the REST Proxy to connect to another container (bootstrap servers), you need to use the other container names, not `localhost` 4) Please use the cp-all-in-one Github repo as your starting point https://github.com/confluentinc/cp-all-in-one/blob/6.1.1-post/cp-all-in-one-community/docker-compose.yml#L131-L144 – OneCricketeer Jun 07 '21 at 20:37

0 Answers0