如何使用 docker-compose 设置独立 mosquitto MQTT 代理
docker-compose.yml
docker-compose.yml
services:
mosquitto:
image: eclipse-mosquitto
network_mode: host
volumes:
- ./config:/mosquitto/config
- ./data:/mosquitto/data
- ./log:/mosquitto/log现在创建 config/mosquitto.conf
mosquitto.conf
persistence true
persistence_location /mosquitto/data/
log_dest file /mosquitto/log/mosquitto.log
listener 1883
## 认证 ##
# allow_anonymous false
password_file /mosquitto/config/mosquitto.passwd现在使用以下命令创建第一个用户
docker-compose run mosquitto mosquitto_passwd -c /mosquitto/config/mosquitto.passwd mosquitto
create_mosquitto_user.sh
docker-compose run mosquitto mosquitto_passwd -c /mosquitto/config/mosquitto.passwd mosquitto你可以可选地使用 -b(批处理)标志而不是 -c 创建更多用户,在命令行上提供密码:
docker-compose run mosquitto mosquitto_passwd -b /mosquitto/config/mosquitto.passwd seconduser shoaCh3ohnokeathal6eeH2marei2o
add_mosquitto_user.sh
docker-compose run mosquitto mosquitto_passwd -b /mosquitto/config/mosquitto.passwd seconduser shoaCh3ohnokeathal6eeH2marei2o现在使用以下命令启动 mosquitto
docker-compose up
docker_compose_up.sh
docker-compose up我们使用 network_mode: host 运行 mosquitto。Mosquitto 默认监听端口 1883(MQTT)。你可以使用 config/mosquitto.conf 配置更多服务,更多信息请参见此 StackOverflow 帖子。
Check out similar posts by category:
MQTT
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow