'How do I set auto.create.topics.enable=true in docker image johnnypark/kafka-zookeeper so that new topics are created automatically?

In docker image johnnypark/kafka-zookeeper new topics are not created automatically. How do I set auto.create.topics.enable=true in this docker image johnnypark/kafka-zookeeper so that new topics are created automatically?



Solution 1:[1]

If you are using wurstmeister image for Kafka, you can add KAFKA_CREATE_TOPICS environment variable to auto create a topic when runing the container.

Your docker-compose file might look as follows:

version: "2"


Services:

kafka-1:
image: confluentinc/cp-kafka:latest

ports:
  - "19092:19092"
depends_on:
  - zookeeper-1
  - zookeeper-2
  - zookeeper-3
environment:
  KAFKA_BROKER_ID: 1
  KAFKA_ZOOKEEPER_CONNECT: zookeeper-1:12181,zookeeper-2:22181,zookeeper-3:32181
  KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka-1:19092
  KAFKA_CREATE_TOPICS: "topic1:1:1,topic2:1:1"

The first parameter is for the number of partionions, the second is for replication factor. For the above kafka configuration, the topic will have 1 partition and 1 replication-factor. You can find out more here

Solution 2:[2]

Add the necessary environment variable to the image, AUTO_CREATE_TOPICS=true

https://github.com/hey-johnnypark/docker-kafka-zookeeper/blob/master/assets/scripts/start-kafka.sh#L74

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Markus
Solution 2 OneCricketeer