Most of the online docker installation kafka environment tutorials will use the following command
docker run -d --name kafka -p 9092:9092 \
-e KAFKA_BROKER_ID=0 -e KAFKA_ZOOKEEPER_CONNECT=192.xxx.xxx.xxx:2181 \
-e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://192.xxx.xxx.xxx:9092 -e \
KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 -t bitnami/kafka:2.7.0
-
--name="Container new name" specifies a name for the container;
-
-d: Run the container in the background and return the container ID, that is, start the daemon container (running in the background);
-
-p: Specify port mapping, lowercase p
When starting the kafka container, it was found that the container did not start normally, and the prompt was found by viewing the log:
- View log command
docker logs kafka
- log error message
INFO ==> ** Starting Kafka setup **
15:04:41.47 ERROR ==> The KAFKA_CFG_LISTENERS environment variable does not configure a secure listener. Set the environment variable ALLOW_PLAINTEXT_LISTENER=yes to allow the container to be started with a plaintext listener. This is only recommended for development.
15:04:41.48 ERROR ==> The KAFKA_ZOOKEEPER_PROTOCOL environment variable does not configure a secure protocol. Set the environment variable ALLOW_PLAINTEXT_LISTENER=yes to allow the container to be started with a plaintext listener. This is only recommended for development.
This is because the environment variable ALLOW_PLAINTEXT_LISTENER was not specified when starting the container to allow the use of the PLAINTEXT listener.
Add the specified environment variable when starting the command
-e ALLOW_PLAINTEXT_LISTENER=yes
docker run -d --name kafka -p 9092:9092 \
-e KAFKA_BROKER_ID=0 -e KAFKA_ZOOKEEPER_CONNECT=192.xxx.xxx.xxx:2181 \
-e ALLOW_PLAINTEXT_LISTENER=yes \
-e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://192.xxx.xxx.xxx:9092 -e \
KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 -t bitnami/kafka:2.7.0
success: