docke和docker-compose环境自己解决
、
- version: "3"
- 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
- persistence true
- listener 1883
- persistence_location /mosquitto/data
- log_dest file /mosquitto/log/mosquitto.log
-
- # 关闭匿名模式
- #allow_anonymous true
- # 指定密码文件
- #password_file /mosquitto/config/pwfile.conf
- [mqtt]$ docker-compose up -d
- Creating network "mqtt_default" with the default driver
- Pulling mqtt (eclipse-mosquitto:2)...
- 2: Pulling from library/eclipse-mosquitto
- 213ec9aee27d: Pull complete
- c38859dc10af: Pull complete
- 20f8f1ac2856: Pull complete
- Digest: sha256:dbb267884bada100906702758cc2cbf334047f2837a52ae57ff272ea1ef6a99e
- Status: Downloaded newer image for eclipse-mosquitto:2
- Creating mqtt ... done
进入容器内部
docker exec -it mqtt sh
生成文件 创建密码
touch /mosquitto/config/pwfile.conf
chmod -R 755 /mosquitto/config/pwfile.conf
# 使用mosquitto_passwd命令创建用户,admin是用户名,admin123是密码
mosquitto_passwd -b /mosquitto/config/pwfile.conf admin admin_23
退出
exit 或者 Ctrl + D
- [mqtt]$ docker exec -it mqtt bash
- OCI runtime exec failed: exec failed: container_linux.go:367: starting container process caused: exec: "bash": executable file not found in $PATH: unknown
- [tly@sdmkdev1 mqtt]$ docker exec -it mqtt sh
- / # touch /mosquitto/config/pwfile.conf
- / # chmod -R 755 /mosquitto/config/pwfile.conf
- / # mosquitto_passwd -b /mosquitto/config/pwfile.conf admin admin123
- / # exit
- [mqtt]$ docker-compose restart
- Restarting mqtt ... done

