1、docker拉取
docker pull eclipse-mosquitto
2、查看镜像
docker images
3、建立配置目录
mkdir -p /mnt/mosquitto/config
mkdir -p /mnt/mosquitto/data
mkdir -p /mnt/mosquitto/log
4、分配权限
chmod -R 755 /mnt/mosquitto
chmod -R 777 /mnt/mosquitto/log
5、创建配置文件
touch mosquitto.conf
配置内容:
# 关闭匿名模式
allow_anonymous false
# 指定密码文件(运行docker前,docker里没有这个文件,需要进入容器创建)
# password_file /mosquitto/config/pwfile.conf
#持久化本地存储
persistence true
persistence_location /mosquitto/data
#日志的保存文件
log_dest file /mosquitto/log/mosquitto.log
# mqtt 这个端口是mqtt默认用的,尽量别改
listener 1883
protocol mqtt
# websocket 端口根据自己需要修改
listener 1884
protocol websockets
6、运行容器
docker run -it \
--name=mosquitto --privileged \
-p 1883:1883 -p 1884:1884 \
-v /mnt/mosquitto/config/mosquitto.conf:/mosquitto/config/mosquitto.conf \
-v /mnt/mosquitto/data:/mosquitto/data \
-v /mnt/mosquitto/log:/mosquitto/log \
-d eclipse-mosquitto
7、添加账号
# 进入docker 容器
docker exec -it mosquitto sh
# 进入配置
cd /mosquitto/config
# 创建密码配置文件
touch pwfile.conf
# 添加账号密码
mosquitto_passwd -b /mosquitto/config/pwfile.conf test test
# 创建完成后退出容器,先ctrl+p 然后 ctrl+q
# 重启docker
docker restart 容器id
标签:log,mnt,eclipse,mosquitto,Liunx,conf,docker,config
From: https://www.cnblogs.com/kanie-life/p/16885206.html