网上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侦听器。
启动命令时加上指定环境变量文章来源:https://www.toymoban.com/news/detail-508366.html
-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
成功:
文章来源地址https://www.toymoban.com/news/detail-508366.html
到了这里,关于Docker环境 运行Kafka容器失败的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!