Docker MQTT Broker for easy service manageability

Docker MQTT Broker
By Ranjith kumar DSM July 9, 2018

Docker is one of the leading container application that is used most widely used in 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 is 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

 

1) Ubuntu 14.04 

2) Docker 1.6.2

3) Mysql 5.5

Setting up the MySQL

We recommend MySQL to be run on a physical machine than a container 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.5

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 containers and other machines to access the MySQL.  

 

$ gedit /etc/mysql/my.cnf

     bind-address = 127.0.0.1to 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 container. 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 container 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 the  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

 

 [email protected]<yourmachinename>$ 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

 

[email protected] # 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

Download now to  get started now to set up your own Docker MQTT Broker

Download FREE MQTT Broker

Feel free to contact support for any questions or feedback. 

 

Must Read Other Related Post