Easy EmonCMS docker install?

Hello, Is there such a thing as an easy install for EmonCMS ?, I’m thinking of a one line Bash script, I tried from documents but couldn’t get the install to work. I mentioned a while ago to Dockstarter.com if they could include EmonCMS in there very good installer but I don’t think there was much interest, I did though get Node-red added to the list.

Hi @myozone - welcome to EmonCMS, nice to have you around.

Quite a few of us are using openenergymonitor/emoncms:

https://hub.docker.com/r/openenergymonitor/emoncms

and we’ve been chatting about various things in this topic:

Were those the install instructions you were following? If so, what tripped you up?

It might be best to respond in that other thread if you’d like to chat about using the Docker setup because then people looking for Docker info will learn from your experience.

Thanks

Thanks for the reply, No those aren’t the instructions I followed I can’t find the ones I followed right now. I couldn’t understand what I did wrong with four simple commands, although I have just noticed I also have Shinobi CCTV also on port 8080 :roll_eyes: that could be the issue. I’m just ‘playing’ at the moment with Docker on a Ubuntu Oracle VM on my laptop, then move over to PI 4 maybe. I just wanted to play with Dockstarter.com but thought it would be nice to have EmonCMS running on the same Docker install. I’ve had EmonCMS running on a PI 2 for years from an image I downloaded from a guy in Norway I’ll have a go with your link and see how that goes.

I’ve just run the four commands everything appeared to install ok but no access via the webpage on 8080


1 Like

Hi @myozone

I’m sure you already thought of this, but the 172.x address for the container is not the 192.x address. I’m assuming you have some virtualization and then networking bridging going on.

To debug, just exec into the container and curl it’s localhost.

docker exec "container-name-or-id" curl localhost

Then you’ll know if it’s not started properly (in which case look in the container logs) or if you are having network re-direction fun (look at the thing wrapping docker to check it’s bridging 8080 too).

I think it’s a permissions issue as all other containers work ok even with the internal docker 172.x addressing.

[email protected]:~$ docker exec “emoncms-docker_web_1” curl localhost
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 274 100 274 0 0 39142 0 --:–:-- --:–:-- --:–:-- 39142

403 Forbidden

Forbidden

You don't have permission to access this resource.


Apache/2.4.38 (Debian) Server at localhost Port 80

It’s running, but I’ll look into permissions. I’ve not really used Docker therefore, a steep learning curve for me.

For a Virtual Environment, the other alternative is Proxmox VE. I run Emoncms in a PVE instance installed on an old laptop, then an Ubuntu container in that. Simple, low resources and built-in UPS!

My plan was to use Docker and have everything on one PI 4, this testing now is temporary playing to get it to work and get used to Docker. I’ve tried a new VM install of Ubuntu and install Docker then the EmonCMS install above with the same issue as above, I thought it might have been DockStarter screwing things up or Shinobi I had on the same port 8080.

Sorry @myozone - I only use Docker native on a native Linux machine where the networking is vastly simpler. I don’t know about all these clever nesting approaches.

I think I need to learn more Docker first, little knowledge and all that. That’s more or less what I did, native linux, spun a new Ubuntu 20.04 VM and added Docker the four install lines.

Got it working by adding the command ./bin/setup_dev_repositories before docker-compose up

$ docker pull openenergymonitor/emoncms
$ git clone https://github.com/emoncms/emoncms-docker
$ cd emoncms-docker
$ ./bin/setup_dev_repositories

sudo apt install docker-compose

$ docker-compose up

Dave.

2 Likes

I can try writing a more complete guide once I figure out some details. I am running it on armv7 but should be able to run on most platforms with the same instructions (including armv8, amd64 or whatever as long as there are images available) But the overall workflow that I did was:

Create a directory structure

  • /emoncms-project
  • /emoncms-project/html
  • /emoncms-project/www
  • /emoncms-project/php
  • /emoncms-project/nginx
  • /emoncms-project/certificates
  • /emoncms-project/emoncms
  • /emoncms-project/emoncms/data
  • /emoncms-project/logs
  • /emoncms-project/python
  • /emoncms-project/configs

in the root project directory create a docker-compose.yml file
your servers would be

  • nginx
  • mysql
  • redis
  • mosquitto
  • python
  • php
  • app-data

The following servers do not need their own Dockerfile. Just configure them directly using the docker-compose.yml

  • mysql: I used mariadb. Configure username/password and the proper directory to store the database files. Put the optimizations that you need on the docker-compose.yml. Expose port 3306 or have it write the socket file into a mounted directory so you can access it from elsewhere.

  • redis: not much configuration needed. Just expose the relevant port

  • mosquitto: stock mosquitto image. Make a mosquitto.conf file and use the docker-compose directives to point towards it. Expose the relevant port. I am still working on configuring this to have the server point towards an upstream server to interface with HomeAssistant.

The following services, in addition to the docker-compose.yml configuration, will also need their own Dockerfile in their respective subdirectory.

  • php: expose port 9001. Mount the volumes as in app-data. If using serial port for input you need to read the docker config on how to allow the container to use the host’s serial port.

  • python: Mount the volumes as in app-data. Also may need to share host’s serial port.

  • nginx: mount the volumes in app-data. Expose and link ports 443 and 80 to the main host. Link with php, mysql, redis, and mosquitto. No need to link to mysql if sharing the socket file. This will be marginally more efficient and secure but I didn’t want to mess with something different than the plain network connectivity.

You need Dockerfile in each of the following subdirectories

  • php → make sure you use an image > 7.2. Install the requirements for Emoncms. You will also need to write a shell script to run the feedwriter and the mqtt services on start and to kill the container if the services stop. Recommend not using a lean distribution. Use the image based on Bullseye. The demandshaper service would also need to be run in this container.

  • python → can use the small Alpine image. Just need to pip redis and pyserial. This runs the service-runner script but I have not been able to do much with it. Have the image execute the service-runner.py script upon starting.

→ nginx → Could potentially use Apache. Or really any other webserver. Configure a default.conf file with the apache rewrite directives equivalent, also point the default.conf to the ssl certificates if interested. Point the webserver root to /var/www/html. Then copy the file to overwrite the default.conf of the stock image

Finally,

run sudo docker-compose build . Wait. A lot
run sudo docker-compose up -d (do not use the -d flag if having issues… that way you will get to see what the containers are doing)

now run sudo docker exec -it mysql-container /bin/bash
you will get into the mysql container. Run the cli tool to create a user/password and a database for emoncms. Make sure to grant all privileges to the database. Get out of the container.

copy the emoncms files into /emoncms-project/www/html
copy the modules that you want into /emoncms-project/www/html/modules

modify the emoncms-project/www/html/settings.ini

  • your mysql database host is ‘mysql’
  • put the mysql username, password, and database name you configured on the first run of the mysql container
  • your redis host is ‘redis’
  • your mosquitto host is ‘mosquitto’. Configure authentication if you set it up

modify /emoncms-project/www/html/scripts/phpmqtt.php.
Need to change the default directory from …/…/…/ to just …/

modify /emoncsm/project/www/html/scripts/service-runner/service-runner.py
modify the initialization string on the Redis server with host=‘redis’

And… lastly… restart everything

sudo docker-compose down
sudo docker-compose build
sudo docker-compose up -d

And you should be ready! your emoncms instance would be at https://localhost:443 and http://localhost.