Run mosquitto in a docker container on the PI
Since I want to migrate all domotica software to my raspberry PI (or perhaps PI’s) it is time to say good bye to my windows mosquitto instance running on my current windows domotica server. Of course I will use docker to run mosquitto also.
I searched the web a bit, and perhaps I didn’t search well enough, but I couldn’t find an up-to-date repository for a mosquitto image that will run on the Raspberry PI. The ones I found, were all a year or more old and for example based on debian jessie whereas debian stretch is the standard now.
So, based on a existing docker file I found on the web, I created a new mosquitto docker image for the Raspberry PI. I have uploaded it to my repository so it can be used by myself, and perhaps others who have looked for one too 🙂
The image can be found here.
As I mentioned in my previous post I already have a mount to my NAS in which I want to store my domoticz data. The mount on the PI is
/home/pi/dockerdata
On this mount I created the necessary sub folders for mosquitto. For mosquitto to work a basic config file should be put in the config folder. As a bare minimum it should have the following contents.
pid_file /var/run/mosquitto.pid persistence true persistence_location /mosquitto/data log_dest file /mosquitto/log/mosquitto.log
The mosquitto image can be installed as follows. I have added the –reatart option so the container is automatically started when for example the PI has been rebooted.
docker run --name=mosquitto \ --restart unless-stopped \ -d \ -e TZ=Europe/Amsterdam \ -p 1883:1883 \ -v /home/pi/dockerdata/mosquitto/config:/mosquitto/config \ -v /home/pi/dockerdata/mosquitto/data:/mosquitto/data \ -v /home/pi/dockerdata/mosquitto/log:/mosquitto/log \ dromer1967/arm32v7-mosquitto
And behold, mosquitto is running in docker on the PI.
Install domoticz on the Raspberry PI in a docker container part 2: using linux server image
In a previous post I showed how I installed domoticz in a docker container using the documentation on the WIKI.
Since I now need to start using domoticz for ‘real’ (since the razberry daughterboard on my ‘production’ PI seems to have died on me) I wanted to update the container with the latest version. Although I no longer have to do the two part install (see my previous post) I searched for an alternative which would be simpler to use and also up-to-date. That is when I came across the linux server.io site which also has a domoticz image available. I tried to install that and it all seems a lot simpler than the one from Joshuacox. Well at least for a domoticz/docker beginner like me!
Since I am using docker on a Raspberry PI3 I needed the ARM version of the domoticz image which can be found here.
As I mentioned in my previous post I already have a mount to my NAS in which I want to store my domoticz data. The mount on the PI is
/home/pi/dockerdata
After removing the old domoticz container and images and cleaning up the mapped config folder on the NAS, I then installed the new domoticz instance.
sudo docker run --name=domoticz \ --restart unless-stopped \ -d \ -t \ -p 1443:1443 \ -p 6144:6144 \ -p 8080:8080 \ -v /home/pi/dockerdata/domoticz:/config \ -e TZ=Europe/Amsterdam \ --device=/dev/ttyUSB0 \ lsioarmhf/domoticz
I no longer use the –privileged flag now because it’s more secure. Mapping the USB device seems to work just as fine.
After starting the container I checked the running domoticz instance on
http://<ip-from-your-pi>:8080
Unfortunately domoticz seemed not to be running. After inspecting the container logs, it turned out that an SSL key was generated for domoticz so it could be accessed using SSL. However, generating such a key on a Raspberry PI 3 takes quite a long time (in my case it took about 30-45 minutes!).
After I drank a nice cup of tea, and such…, domoticz was finally up.
So I now can start to reset all my ZWave nodes (since they can’t be removed from a dead ZWave controller) and include the in my new ZWave ‘production’ environment.
Install domoticz on the Raspberry PI in a docker container
On the domoticz WIKI is a page on how to install domoticz in a docker container. You can find it here.
There were however some items on that page, ‘cat cid’ and ‘pwd’ I did not quite understand being a newcomer in Docker. For those that have come accross the same issue here is what I did to get it running (mainly copying stuff from the WIKI page).
I already have a mount to my NAS in which I want to store my domoticz data. The mount on the PI is
/home/pi/dockerdata
I created a folder called domoticz in dockerdata to store the data from domoticz
mkdir /home/pi/dockerdata/domoticz
Now we have to start a first instance of domoticz from which we can copy the config files. I haven’t got a clue why this process needs two steps and two containers, but I’ll stick to the manual because I don’t know what else to do 🙂
So to run the first container
sudo docker run --name=domoticz \ --privileged \ --cidfile="cid" \ -d \ -t \ -p 8080:8080 \ joshuacox/mkdomoticz:arm
We can now copy the config files from the running container into our created domoticz folder
sudo docker cp domoticz:/config /home/pi/dockerdata/domoticz
Now this container is no longer used and can be removed
sudo docker stop domoticz sudo docker rm domoticz
And we can finally create our ‘real’ domoticz container using the created config folder. Please note that I included an extra parameter to set the timezone correctly in the domoticz container.
sudo docker run --name=domoticz \ --privileged \ -d \ -t \ -p 8080:8080 \ -v /home/pi/dockerdata/domoticz:/config \ -e TZ=Europe/Amsterdam \ joshuacox/mkdomoticz:arm
And we are done. You can check the running domoticz instance on
http://<ip-from-your-pi>:8080