我是 mqtt 新手,我正在尝试简单地启动一个可以测试的本地实例。
执行时
docker run -it -p 1883:1883 --restart always -v mosquitto.conf:/home/juliette/mosquito.conf --name mqtt eclipse-mosquitto:2.0.7
我得到以下输出:
1615963221: mosquitto version 2.0.7 starting
1615963221: Config loaded from /mosquitto/config/mosquitto.conf.
1615963221: Starting in local only mode. Connections will only be possible from clients running on this machine.
1615963221: Create a configuration file which defines a listener to allow remote access.
1615963221: Opening ipv4 listen socket on port 1883.
1615963221: Opening ipv6 listen socket on port 1883.
1615963221: Error: Address not available
1615963221: mosquitto version 2.0.7 running
并且无法与 mqtt 客户端连接:
mqtt sub --topic test
Server closed connection without DISCONNECT.
据我发现,当没有配置监听器但我配置了监听器时,显然会发生错误,这是我的mosquito.conf:
listener 1883
allow_anonymous true
persistence true
persistence_location /mosquitto/data/
log_dest file /mosquitto/log/mosquitto.log
port 1883
我还尝试将端口更改为 8883,因为在一篇文章中有人提到更大的端口可能会解决问题,但这也不起作用。
有人可以告诉我我做错了什么吗?
最佳答案
您的启动命令很接近,但不正确。应该是:
docker run -it \
-p 1883:1883 \
--restart always \
-v /home/juliette/mosquito.conf:/etc/mosquitto/mosquitto.conf \
--name mqtt \
eclipse-mosquitto:2.0.7
配置文件位于 /etc/mosquitto
...除非他们在版本 2 中移动了它。
您可能还想为 mqtts/TLS 连接添加 -p 8333:8333
行。
编辑:我在您的日志文件输出中看到它说配置是从 /mosquitto/config/mosquitto.conf
加载的...所以如果 -v/home/juliette/mosquitto.conf:/etc/mosquitto/mosquitto.conf
行不起作用,将其更改为 -v/home/juliette/mosquitto.conf:/mosquitto/config/mosquitto.conf
关于docker - Eclipse-蚊子 "Address not available",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66668144/