赞
踩
参考: https://blog.csdn.net/weixin_43790195/article/details/104633271
docker-compose-mqtt.yml
version: "3.7"
services:
mqtt:
image: eclipse-mosquitto:2
container_name: mqtt
privileged: true
ports:
- 1883:1883
- 9001:9001
volumes:
- ./config:/mosquitto/config
- ./data:/mosquitto/data
- ./log:/mosquitto/log
config文件夹中放
mosquitto.conf
persistence true
listener 1883
persistence_location /mosquitto/data
log_dest file /mosquitto/log/mosquitto.log
# 关闭匿名模式
# allow_anonymous false
# 指定密码文件
# password_file /mosquitto/config/pwfile.conf
docker-compose -f docker-compose-mqtt.yml up -d
此时连接时没有密码的
密码配置 分三步
# 关闭匿名模式
allow_anonymous true
# 指定密码文件
password_file /mosquitto/config/pwfile.conf
进入容器内部
docker exec -it mqtt sh
生成文件 创建密码
touch /mosquitto/config/pwfile.conf
chmod -R 755 /mosquitto/config/pwfile.conf
# 使用mosquitto_passwd命令创建用户,admin是用户名,admin_123是密码
mosquitto_passwd -b /mosquitto/config/pwfile.conf admin admin_123
退出
exit 或者 Ctrl + D
docker restart mqtt
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。