Home About us Support Partners SIGN UP NOW
Text Copied
 Home    Blog    Docker MQTT Broker

Docker MQTT Broker for easy service manageability

by Ponlakshmi


docker mqtt broker

Docker is one of the leading section applications that is used most widely for running a well managed deployment environment. Docker MQTT Broker will help you have more control over your IoT production environment. Most than 60% of the servers are using either Ubuntu / Debian for their hosting


You can use the following instructions to run the MQTT Broker on Docker on any of cloud providers like Amazon EC2 or Google Cloud or Microsoft cloud or on premise behind the firewall.

Requirements for Docker MQTT Broker

  • Ubuntu 18.04
  • Docker 20.10.2
  • Mysql 5.7

Setting up the MySQL

We recommend MySQL to be run on a physical machine than a section for the data persistence purpose. Follow the below instructions to set up the MySQL. You have to install the MySQL Server first.

$ sudo apt-get update
$ sudo apt-get install -y mysql-server-5.7

Modify the MySQL configuration. By default the mysql runs at 127.0.0.1 and allows only the local application to connect to it. You have to change it as 0.0.0.0 for application running on sections and other machines to access the MySQL.

$ gedit /etc/mysql/my.cnf
bind-address = 0.0.0.0

Restart the MySQL for the changes to take effect.

$ sudo service mysql restart

Providing data access. The root user of MySQL has access only form the local machine to read and write data into the databases. We need to allow the root user to access data from the section. Connect to the MySQL console from the localhost and then execute the following queries.

$ mysql -u root -p Enter password: <provide your password here>
mysql> GRANT ALL PRIVILEGES ON *.* TO ‘root’@’%’ IDENTIFIED BY ‘root’ WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES

Your MySQL server is all set to connect from any section that runs on your Ubuntu server.

Creating Docker MQTT Broker

Docker needs to be installed in your ubuntu to create the docker image of the MQTT Broker and also run the dockerized MQTT Broker. To install the Docker, run the following command.

$ apt-get install docker.io

Download the Linux version of Bevywise MQTT Broker and Extract it from your /home/ubuntu folder. If you are extracting the archive from some other folder, make sure you use the right reference folder

ubuntu@$ unzip Bevywise_MQTT_Route_Linux.zip

We will be creating a docker image in the name of mqttroute. Create a directory for creating the docker file.

$ mkdir /home/ubuntu/mqttroute

Copy files of the MQTT Broker to the mqttroute folder.

$ cp -rf /home/ubuntu/Bevywise/MQTTRoute/* /home/ubuntu/mqttroute/

Modify the configuration of the MQTT Broker for MySQL connections

$ cd /home/ubuntu/mqttroute/ $ gedit conf/data_store.conf DB_SERVER = MYSQL
DBHOST=<mysql host ip>
MYSQL_USER= <your mysql user>
MYSQL_PASSWORD = <mysql db password>

Create the mount folder where the docker images will be mounted.

$sudo mkdir /bin/mqtt

Create the docker file

$ gedit Dockerfile FROM ubuntu
COPY . /bin/mqtt
CMD [“sh”, “/bin/mqtt/bin/runbroker.sh”]

Build the docker image

# docker build -t mqttroute .

Verify & Run Docker MQTT Broker

# docker images

root@ubuntu # docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
mqtt latest 45f7ee9a1ec7 7 seconds ago 81.15 MB
ubuntu latest 7feff7652c69 4 weeks ago 81.15 MB

Start using the docker command. The following command will run the MQTT Broker as a daemon process. If you are planning to run MQTT Broker in a secure mode, you can refer to our previous blog on ssl certificate creation and placement of the files inside the MQTT Broker.

$ docker run – –restart=always -d -p 8080:8080 -p 1883:1883 -p 10433:10433 mqttroute

Try our MQTT Broker for FREE and experience seamless connectivity.