docker-compose安装mqtt

docke和docker-compose环境自己解决

一、新建文件夹mqtt和文件内部文件

1、编写docker-compose.yml文件 

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

2、config文件新建mosquitto.conf

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

五、MQTTX客户端连接

免费下载、试用 EMQ 产品

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值