# 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)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://kawsing.gitbook.io/opensystem/docker-cong-an-zhuang-dao-ying-yong-ru-men-pian/untitled-4.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
