用docker 封装mosquitto并配置用户名和密码

先创建一个目录mosquitto

创建一个Dockerfile文件内容:

FROM eclipse-mosquitto
COPY ./pwfile /etc/mosquitto/pwfile
RUN chmod 777 /etc/mosquitto/pwfile && mosquitto_passwd -U /etc/mosquitto/pwfile

// 创建密码:

mosquitto_passwd [ -c | -D ] passwordfile username

mosquitto_passwd -b passwordfile username password

mosquitto_passwd -U passwordfile

创建pwfile 内容:

user:pwd

创建mosquitto.conf

pid_file /var/run/mosquitto.pid
persistence true
persistence_location /mosquitto/data
allow_anonymous false
password_file /etc/mosquitto/pwfile

port 1883
listener 11880
protocol websockets

创建一个启动的脚本 start.sh

docker run --name m2m_mosquitto -t -d -v $PWD/mosquitto.conf:/mosquitto/config/mosquitto.conf -p 32011:1883 -p 32012:11880 m2m-mosquitto


 

展开阅读全文

没有更多推荐了,返回首页