docker eclipse-mosquitto 运行 仅在本地主机上

docker eclipse-mosquitto run only on localhost

我想使用 docker eclipse-mosquitto 只是为了在本地机器上进行通信。 mosquitto.conf 我需要哪些设置才能使 mosquitto 代理仅在本地主机上可见而不从外部可见?由于第二只蚊子运行,1883端口被封锁,我正在使用1884端口。

这是我的:

port 1884
bind_address 127.0.0.1

从外面可见。

port 1884
bind_address localhost

给出错误 Error: Address not available

绑定到 docker-ip

port 1884
bind_address 172.17.0.1

给出错误 Error: Address not available

我能做什么?

好的,自己解决了:

运行 docker 带有附加选项 --network="host" 而不是 mosquitto.conf:

port 1884
bind_address 127.0.0.1

完成任务。

你的回答是错误的方法,你应该只真正使用 --network="host" 来处理需要打开原始套接字或从本地网络接收广播消息的事情。

正确答案是不使用mosquitto.conf文件中的bind_address选项,使用docker-p选项正确做端口映射(docs).

例如

docker run exec -rm -p 127.0.0.1:1884:1884/tcp mosquitto

这里-p 127.0.0.1:1884:1884将容器中的1884端口映射到主机上绑定到loopback ip(127.0.0.1)的1884端口。