Docker环境 运行Kafka容器失败

网上docker 安装kafka环境教程大多数会采用下面命令

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=“容器新名字” 为容器指定一个名称;

  • -d: 后台运行容器并返回容器ID,也即启动守护式容器(后台运行);

  • -p: 指定端口映射,小写p

启动kafka容器时发现容器并没有正常启动,通过查看日志发现提示:

  • 查看日志命令
docker logs kafka
  • 日志错误提示
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.

在这里插入图片描述
这是因为在启动容器时没有指定环境变量ALLOW_PLAINTEXT_LISTENER 允许使用PLAINTEXT侦听器。

启动命令时加上指定环境变量

-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

成功:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_31686241/article/details/125966127