简体   繁体   English

无法订阅Docker Eclipse-Mosquitto Broker

[英]Can't subscribe to Docker Eclipse-Mosquitto Broker

I have the eclipse-mosquitto image up and running, also a publisher in another container that connects and publishes successfully. 我启动并运行了eclipse-mosquitto映像 ,并且在另一个成功连接并发布容器的容器中创建了发布者。 I can shell into the broker container and use mosquitto_sub to retain the messages, but when I try to subscribe from the local machine the connection is refused. 我可以将外壳程序装入代理容器,并使用mosquitto_sub保留消息,但是当我尝试从本地计算机订阅时,连接被拒绝。

This is the command I've used to start the container: 这是我用来启动容器的命令:

docker run --name mqtt --restart=always --net=host -tid  eclipse-mosquitto

The --net=host flag is used so I can just use localhost everywhere. 使用--net=host标志,因此我可以在任何地方使用localhost And this is how I tried to subscribe, which works from within the container: 这就是我尝试订阅的方式,它可以在容器内工作:

mosquitto_sub -h localhost -t TOPIC

Is there a Docker flag or some other option that I've missed preventing me to subscribe from the local machine? 是否有我错过的Docker标志或其他某些选项阻止我从本地计算机订阅? Or would a subscriber in a Docker container work? 还是Docker容器中的订阅者可以工作?

On Windows only, it is necessary to set the publish flag for the specific port, so the correct command to start the broker is 仅在Windows上,必须为特定端口设置发布标志,因此启动代理的正确命令是

docker run --name mqtt -p 1883:1883 -tid eclipse-mosquitto

while the publisher is started with 发布者开始时

docker run -it --net=host mosquitto-pub

Then a subscriber on the local machine is started without problem by simply 然后,只需简单地启动本地计算机上的订户即可

mosquitto_sub -t TOPIC

Note: The --net=host flag for the broker can't be used with the publish flag. 注意:代理的--net=host标志不能与publish标志一起使用。 Not sure why it's still necessary for the publisher though. 虽然不确定为什么对发布者仍然有必要。

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

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