{"id":22273816,"url":"https://github.com/geeksloth/setup-mosquitto-docker","last_synced_at":"2026-04-28T20:35:43.219Z","repository":{"id":263125196,"uuid":"889418883","full_name":"geeksloth/setup-mosquitto-docker","owner":"geeksloth","description":"A short note of setting up the mosquitto MQTT broker with Docker container.","archived":false,"fork":false,"pushed_at":"2024-12-05T07:41:31.000Z","size":45,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-30T14:48:37.511Z","etag":null,"topics":["docker","mqtt","mqtt-broker","mqtt-server"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/geeksloth.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-16T10:32:42.000Z","updated_at":"2024-12-05T07:41:34.000Z","dependencies_parsed_at":"2024-11-16T11:39:20.126Z","dependency_job_id":null,"html_url":"https://github.com/geeksloth/setup-mosquitto-docker","commit_stats":null,"previous_names":["geeksloth/setup-mosquitto-docker"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geeksloth%2Fsetup-mosquitto-docker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geeksloth%2Fsetup-mosquitto-docker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geeksloth%2Fsetup-mosquitto-docker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geeksloth%2Fsetup-mosquitto-docker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/geeksloth","download_url":"https://codeload.github.com/geeksloth/setup-mosquitto-docker/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245502318,"owners_count":20625949,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","mqtt","mqtt-broker","mqtt-server"],"created_at":"2024-12-03T13:16:27.223Z","updated_at":"2026-04-28T20:35:38.196Z","avatar_url":"https://github.com/geeksloth.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# setup-mosquitto-docker\nA short note of setting up the mosquitto MQTT broker with Docker container.\n\n\n\n## 1. Docker installation\n\u003e [!TIP]\n\u003e This step is optional. If you have already installed Docker in your system and pulled the image, skip to the next step.\n\nFor Debian-based, ie. Ubuntu, Raspberry Pi, ...\n```bash\nsudo apt-get update \u0026\u0026 sudo apt-get install -y docker.io\n```\n```bash\nsudo usermod -aG docker $USER\n```\nFor macOS\n```bash\nbrew install --cask docker\n```\n\nTo pull the Mosquitto Docker image, run the following command:\n\n```bash\ndocker pull eclipse-mosquitto\n```\n\n\n## 2. Configuration\nCreate necessary directories:\n```bash\nmkdir ~/mosquitto \u0026\u0026 mkdir ~/mosquitto/config \u0026\u0026 mkdir ~/mosquitto/data \u0026\u0026 mkdir ~/mosquitto/log\n```\nDownload configuration template file: [mosquitto.conf](https://github.com/geeksloth/setup-mosquitto-docker/blob/main/mosquitto.conf), and save to `~/mosquitto/config/mosquitto.conf`, then modify it with following information:\n```conf\nallow_anonymous false\nlistener 1883\n#protocol websockets\npassword_file /mosquitto/config/passwordfile\npersistence true\npersistence_location /mosquitto/data/\nlog_dest file /mosquitto/log/mosquitto.log\n```\n\u003e [!NOTE]\n\u003e `/mosquitto` in this file is not the same as `~/mosquitto` from the previous step. These directory will be mounted to a Docker container and working inside there.\n\nCreate a `passwordfile` to store user and password for the service.\n```bash\nsudo touch ~/mosquitto/config/passwordfile\n```\n\nRun a container using the new configuration:\n```bash\ndocker run -it -d -p 1883:1883 -v \"$HOME/mosquitto/config:/mosquitto/config\" -v \"$HOME/mosquitto/data:/mosquitto/data\" -v \"$HOME/mosquitto/log:/mosquitto/log\" --name mqtt-broker eclipse-mosquitto\n```\n\n\n## 3. Username and password\nExec  into the mqtt container\n```bash\ndocker exec -it mqtt-broker sh\n```\n\nCreate new password file and add user and it will prompt for password\n```bash\nmosquitto_passwd /mosquitto/config/passwordfile user1\n```\n\nAdd additional users\n```bash\nmosquitto_passwd /mosquitto/config/passwordfile user2\n```\n\nTo delete user:\n```bash\nmosquitto_passwd -D /mosquitto/config/passwordfile \u003cuser-name\u003e\n```\n\n\u003e [!TIP]\n\u003e type `chmod 0700 /mosquitto/config/passwordfile` to change the permission, and `chown root /mosquitto/config/passwordfile` to change the owner.\n\u003e type `exit` to exit the container\n\n\n\n## 4. Testing the setup\nYou can test the Mosquitto setup using an MQTT client like `mosquitto_pub` and `mosquitto_sub`.\n\nTo subscribe the topic:\n```bash\nmosquitto_sub -h localhost -t \"test/topic\" -u \u003cuser\u003e -P \u003cpassword\u003e\n```\n\nTo publish a message to the topic:\n```bash\nmosquitto_pub -h localhost -t \"test/topic\" -m \"Hello, MQTT\" -u \u003cuser\u003e -P \u003cpassword\u003e\n```\n\nThis should help you set up and test the Mosquitto MQTT broker using Docker.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeeksloth%2Fsetup-mosquitto-docker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgeeksloth%2Fsetup-mosquitto-docker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeeksloth%2Fsetup-mosquitto-docker/lists"}