Every now and then I do some experimentation just to discover what the possibilities are. Usually this results in something good. But sometimes I make a mess of it. Unfortunately the pimatic intstallation including configuration and plugins can take some effort and, especially on a Pi 1, some time to install. Docker with a preconfigured pimatic image to the rescue!
Skip this If you know how or already have raspbian running
- Flash the latest raspian image to SD card
- Add a file without content called "ssh" to enable ssh on boot
- Login using ssh
sudo nano /etc/dhcpcd.confand add:
interface eth0 static ip_address=192.168.47.31/24 static routers=192.168.47.1 static domain_name_servers=126.96.36.199
- Login again
sudo apt-get update
sudo apt-get -u dist-upgrade
Let the docker install script do it's magic:
sudo curl -sSL https://get.docker.com | sh
Docker-compose is required to properly run docker containers
sudo apt-get -y install python-pip then run
sudo pip install docker-compose
To enable docker for the pi user type
sudo usermod -aG docker pi followed by
sudo service docker restart
After this log out and log in again.
Now you can run docker whitout having to type sudo in front of it each time
Run a basic pimatic image on a Pi, or Pi Zero
docker run -t -i -p 80:80 joshendriks/raspberry-pi-pimatic
On a Pi 2 use
joshendriks/raspberry-pi2-pimatic. On a Pi 3 use
When the container is started type
pimatic.js at the command prompt. Pimatic should start and can be accessed on port 80 of the Pi. (user
When this all works we start creating our own image including your own pimatic configuration.
Build a specific image
Create a docker image is pretty straight forward. On the docker host (your Pi), create a Dockerfile by typing:
The image needs the following
- automatic startup of pimatic
- pimatic-homeduino plugin
- pimatic-mqtt plugin
- my own pymatic config file
To make that happen, add the following to your Dockerfile:
FROM joshendriks/raspberry-pi-pimatic:4 RUN cd /home/pimatic-app && npm install pimatic-homeduino pimatic-mqtt COPY pimatic_confg.json /home/pimatic-app/config.json ENTRYPOINT ["pimatic.js"]
For the above to work your will also need to create a
pimatic_confg.json file. Put it in the same location as
Both files are available on https://github.com/joshendriks/blog-docker-pimatic as well.
Build the docker image:
docker build -t pimaticnode -f Dockerfile.pimaticnode .
Run the docker image:
docker run -p 80:80 --device=/dev/ttyUSB0 -t -i pimaticnode
--device=/dev/ttyUSB0 has been added so that the homeduino plugin can access the physical USB port
Again Pimatic should start and can be accessed on port 80 of the Pi. (user
Start the image on boot
Create a docker-compose file:
Add the following content:
registry: restart: always image: pimaticnode ports: - 0.0.0.0:80:80 devices: - "/dev/ttyUSB0:/dev/ttyUSB0"
Above is the equivalent of
docker run command that we used before.
Again note that
/dev/ttyUSB0 has been added so that the homeduino plugin can access the physical USB port. If you do not have something connected to /dev/ttyUSB0, leave the last two lines out.
Finally run docker-compose file:
sudo docker-compose -f pimaticnode.yml up -d
This will start the container in the background. Because
restart: always is in the
.yml file it will also start the container upon reboot.
That's it, pimatic is now running using docker on a pi!
In my next blog I will dicuss how to have
config.json outside the image and how you can store your own images.