简体   繁体   English

无法从Docker中运行的服务向kafka生成消息

[英]Cannot produce message to kafka from service running in docker

I've a rest service running in docker container on port 5000 which is used to produce message over kafka topic running out of docker container. 我在端口5000上的docker容器中运行了一个REST服务,该服务用于通过kafka主题生成消息,而该主题用尽了docker容器。

I've configure my producer client with below properties :- 我为生产者客户端配置了以下属性:-

bootstrap.servers=localhost:9093

And I've started my contained with below command:- 我已经用下面的命令开始了包含:

docker run -d -p 127.0.0.1:5000:5000 <contained id>

I've also made below configuration to advertise kafka host and port 我还做了以下配置来宣传kafka主机和端口

advertised.host.name=localhost
advertised.port=9093

Despite of having all configuration when I try to produce to a kafka topic then I get below error:- 尽管我尝试制作kafka主题时已进行了所有配置,但还是遇到了以下错误:-

org.apache.kafka.common.errors.TimeoutException: Failed to update metadata after 60000 ms.

Can someone please point where the actual problem is? 有人可以指出实际问题在哪里吗?

In real life, advertised.host.name should never be localhost . 在现实生活中, advertised.host.name绝不能为localhost

In your case, you run your Docker container in bridge networking mode, so it won't be able to reach the broker via localhost , as it will point to the container network, not the host machine. 在您的情况下,您以桥接网络模式运行Docker容器,因此它将无法通过localhost到达代理,因为它将指向容器网络,而不是主机。

To make it work you should set the advertised.host.name and bootstrap.servers to the IP address returned by ifconfig docker0 (might be not docker0 in your case but you get the point). 要使其正常工作,应将advertised.host.namebootstrap.servers设置为ifconfig docker0返回的IP地址(在您的情况下,可能不是docker0,但您明白了)。

Alternatively, you may probably run your container with --net=host , but I think you'd better properly configure the advertised host name. 另外,您也许可以使用--net=host运行容器,但是我认为您最好正确配置发布的主机名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM