I am trying to create kafka topic from docker compose
Here is content of docker-compose.yml file (based on sample files from other posts )
version: '3.9'
networks:
myNetwork:
services:
zookeeper:
image: 'bitnami/zookeeper:latest'
ports:
- '2181:2181'
environment:
- ALLOW_ANONYMOUS_LOGIN=yes
networks:
- myNetwork
kafka_1:
image: 'bitnami/kafka:latest'
user: root
ports:
- '9092:9092'
environment:
- KAFKA_BROKER_ID=1
- KAFKA_LISTENERS=PLAINTEXT://:9092
- KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://127.0.0.1:9092
- KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181
- ALLOW_PLAINTEXT_LISTENER=yes
volumes:
- ./Kafka:/bitnami/kafka
networks:
- myNetwork
depends_on:
- zookeeper
init-kafka:
image: 'bitnami/kafka:latest'
depends_on:
- kafka_1
working_dir: /opt/bitnami/kafka/bin
entrypoint: /bin/bash
networks:
- myNetwork
command:
kafka-topics.sh --create --if-not-exists --topic foo --replication-factor=1 --partitions=3 --bootstrap-server kafka_1:9092
After I running with command
docker compose up -d
I am getting error :
2024-05-12 12:16:15 [2024-05-12 09:16:15,248] WARN [AdminClient clientId=adminclient-1] Connection to node 1 (/127.0.0.1:9092) could not be established. Node may not be available. (org.apache.kafka.clients.NetworkClient)
2024-05-12 12:16:15 [2024-05-12 09:16:15,391] ERROR org.apache.kafka.common.errors.TimeoutException: Timed out waiting for a node assignment. Call: createTopics
2024-05-12 12:16:15 (org.apache.kafka.tools.TopicCommand)
2024-05-12 12:16:15 Error while executing topic command : Timed out waiting for a node assignment. Call: createTopics
And of course topic was not created.
Is there missing something in docker_compose.yml ? Thanks in advance