Setting up emoncms in Docker

As I posted earlier, there’s a github project for setting up emoncms in Docker, but the configuration assumes that a MySQL instance will be set up in a second Docker image and everything built together with docker-compose, which wasn’t what I wanted. I already have MySQL running on the host machine with MythTV and I wanted to use that.

Fortunately, having cloned the project it’s fairly straightforward to get things moving in the right direction. I edited the Dockerfile to add these ENV entries immediately after the FROM, which really isn’t the way to do it and keep your passwords secure, but it will do for me for the moment as I don’t need to share the Docker image anywhere:

ENV MYSQL_HOST=<ip-address>
ENV MYSQL_PORT=3306
ENV MYSQL_DATABASE=emoncms
ENV MYSQL_USER=emoncms
ENV MYSQL_PASSWORD=<password>
ENV REDIS_ENABLED=false
ENV REDIS_HOST=''
ENV REDIS_PORT=6379
ENV REDIS_PREFIX='emoncms'
ENV MQTT_ENABLED=true
ENV MQTT_HOST=<ip-address>
ENV MQTT_USER=emon
ENV MQTT_PASSWORD=<password>
ENV MQTT_BASETOPIC=sensors
ENV PHPFINA_DIR=/var/opt/emoncms/phpfina/
ENV PHPTIMESERIES_DIR=/var/opt/emoncms/phptimeseries/

I changed the topic that emoncms uses to be a bit more intuitive for my use case.

After rebuilding the image I created two local directories, /var/lib/emoncms/phpfina and /var/lib/emoncms/phptimeseries to store some of the data because I think I’d prefer to have it persist over restarts of the container rather than disappear. So my current way to start the package is:

docker run -it -p <ip-address>:80:80 -v /var/lib/emoncms:/var/opt/emoncms emoncms

I’ll put together a systemd configuration for that shortly.

After connecting to the IP address in a browser (which I also need to think about more as perhaps it should have an SSL certificate) I created an account and was then faced with working out what to do next. It really wasn’t clear how I might add sensors of my own into the system. There are templates for some existing devices, but I struggled to find much that was clear regarding how to set up completely new ones. That will be the next step.

This entry was posted in Computing and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *