0

I am trying to setup kafka on my local machine via docker. However everytime I run my docker compose command I receive "Error while executing topic command : Timed out waiting for a node assignment. Call: listTopics"."Error while executing topic command : Timed out waiting for a node assignment. Call: createTopics" From other posts Ive read the reason is because I am not using the 9092 port number. But in my compose file I am.

Any assistance would be appreciated.

Compose File:

version: '3.4'

services:
  zookeeper:
    image: 'bitnami/zookeeper:latest'
    ports:
      - '2181:2181'
    environment:
      - ALLOW_ANONYMOUS_LOGIN=yes
    extra_hosts:
      - "host.docker.internal:host-gateway"

  kafka:
    image: 'bitnami/kafka:latest'
    ports:
    - '9092:9092'
    environment:
      - KAFKA_BROKER_ID=1
      - KAFKA_LISTENERS=PLAINTEXT://:9092
      - KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://host.docker.internal:9092
      - KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181
      - ALLOW_PLAINTEXT_LISTENER=yes
    depends_on:
      - zookeeper
    extra_hosts:
      - "host.docker.internal:host-gateway"

  init-kafka:
    image: confluentinc/cp-kafka
    depends_on:
      - kafka
    entrypoint: [ '/bin/sh', '-c' ]
    command: |
      "
      # blocks until kafka is reachable
      kafka-topics --bootstrap-server host.docker.internal:9092 --list

      #echo -e 'Creating kafka topics'
      kafka-topics --bootstrap-server host.docker.internal:9092 --create --if-not-exists --topic topic1 --replication-factor 1 --partitions 1
      kafka-topics --bootstrap-server host.docker.internal:9092 --create --if-not-exists --topic topic2 --replication-factor 1 --partitions 1

      #echo -e 'Successfully created the following topics:'
      kafka-topics --bootstrap-server host.docker.internal:9092 --list
      "
    extra_hosts:
      - "host.docker.internal:host-gateway"
networks:
  authnetwork:
    driver: bridge

TheProgrammer
  • 1,314
  • 5
  • 22
  • 44
  • You have Kafka running as a container. You don't need `host.docker.internal` anywhere. Replace all references with `kafka:9092`. And remove the `9092:9092` + `extra_hosts` mappings since they aren't used here. You can also replace `confluentinc/cp-kafka` with the `bitmani/kafka:latest` since you don't need to use two different Kafka images – OneCricketeer Apr 25 '23 at 19:00

0 Answers0