> For the complete documentation index, see [llms.txt](https://kawsing.gitbook.io/opensystem/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kawsing.gitbook.io/opensystem/docker-cong-an-zhuang-dao-ying-yong-ru-men-pian/untitled-4.md).

# docker mosquitto mqtt server

```
git clone https://github.com/toke/docker-mosquitto.git
sudo mkdir -p /docker/mqtt/log /docker/mqtt/config /docker/mqtt/data
sudo touch /docker/mqtt/log/mosquitto.log
sudo chmod 666 /docker/mqtt/log/mosquitto.log
cd docker-mosquitto/config/
sudo cp -a * /docker/mqtt/config/
sudo docker run -itd -p 1885:1883 -p 9001:9001 -v /docker/mqtt/config:/mqtt/config -v /docker/mqtt/log:/mqtt/log -v /docker/mqtt/data/:/mqtt/data/ --name mqtt toke/mosquitto
```

發送測試

```
docker exec mqtt mosquitto_pub -t hello -m "helloworld"
```

![](/files/-Lkau-BQasXl0JPijxN4)

## **使用者認證**

進入容器建立帳號密碼

![](/files/-Lkb8jjFAu8yi7dloZH0)

```
# Place your local configuration in /mqtt/config/conf.d/
  
pid_file /var/run/mosquitto.pid

persistence true
persistence_location /mqtt/data/

user mosquitto
#-----------need user auth---------
password_file /mqtt/config/passwd
allow_anonymous false
#---------------------------------
# Port to use for the default listener.
port 1883


log_dest file /mqtt/log/mosquitto.log
log_dest stdout

include_dir /mqtt/config/conf.d
```

mqtt 測試

docker exec mqtt mosquitto\_pub -t hello -m "helloworld" -u user -P password

![](/files/-LkbDxTF6TELH0DrN-NN)
