From a rented server to self hosted

hi

i have a webserver with simply.com, and now i want to use my omv box with docker installed

on simply.com i only use mysql as it has unlimited space, can i do the same in docker? and if so who can guide me if i need help with the initial setup and transfer of data ?

just got docker running… or i tried to

its on a OMV6… docker is installed and running

root@bo-omv:~# docker run hello-world
docker: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: unable to apply apparmor profile: apparmor failed to apply profile: write /proc/self/attr/apparmor/exec: no such file or directory: unknown.
ERRO[0317] error waiting for container:
root@bo-omv:~#

Hello @boelle this sounds like a docker configuration issue rather than something emoncms related, have you tried searching elsewhere? I get a lot of google results if I search for your error?

oh yes, something happend and there are a workaround… now i just need to get it going via portainer

i’m a gui guy by hart so i hate CLI

so yes its running and i used the default 8080

but when i open the page i get a connection refused and currently at a loss as to what is wrong

portainer on port 9000 works fine

btw… is it true that the docker image requires a domain? if so can that requirement be disabled so i can go local?

Does that explain the connection refused?

Hello @boelle not sure why you are getting that error. I’ve just tried spinning up the docker container here on my Ubuntu machine and it worked fine first try.

I would note we don’t actively maintain the docker image, the version of emoncms on there is currently 10.9.21, it looks functional but would be good to update. Our focus for emoncms deployment is the EmonScripts approach, but that’s not really going to help you with your goal of hosting this on your existing omv box.

Im not familiar at all with omv box so not sure where to start with helping on that front.

no problemo, as long i did it correct in portainer then it must be something else

so a domain is not required? i have been told that is a requirement

no domain should not be a requirement. Emoncms works fine via an IP address

got it going… sort of

Error: environment var 'MYSQL_HOST' not defined

Error: environment var 'MYSQL_DATABASE' not defined

Error: environment var 'MYSQL_USER' not defined

Error: environment var 'MYSQL_PASSWORD' not defined

Error: environment var 'MYSQL_PORT' not defined

Error: environment var 'REDIS_ENABLED' not defined

Error: environment var 'REDIS_HOST' not defined

Error: environment var 'REDIS_PORT' not defined

Error: environment var 'REDIS_PREFIX' not defined

Error: environment var 'MQTT_ENABLED' not defined

Error: environment var 'MQTT_HOST' not defined

Error: environment var 'MQTT_USER' not defined

Error: environment var 'MQTT_PASSWORD' not defined

Error: environment var 'MQTT_BASETOPIC' not defined

Error: environment var 'PHPFINA_DIR' not defined

Error: environment var 'PHPTIMESERIES_DIR' not defined

**Warning** : Redis::connect() expects parameter 2 to be int, string given in **/var/www/emoncms/index.php** on line **37**
Can't connect to redis at {{REDIS_HOST}}:{{REDIS_PORT}} , it may be that redis-server is not installed or started see readme for redis installation

did i miss anything with the errors i get?

Hello @boelle

I think this relates to the option to use environment variables to configure emoncms which is usually the approach used with docker.

Are you able to set these environment variables on OMV6 somewhere?

i can add them or load them from an .env file when i deploy the container in portainer

so i would need that one,

dont get stressed over this, you run the software and make a bit of money from that, and like any good merchant that should come first

I’ve updated the emoncms docker image to PHP8.0, alongside other related package updates. The emoncms_mqtt script is also now running in a supervisor thanks to @jamesfidell, if you have an MQTT server running elsewhere you can connect to this to receive data in emoncms.

To enable MQTT, change the settings in default.docker-env. E.g:

# MQTT (needs to be running elsewhere)
MQTT_ENABLED=true
MQTT_HOST=192.168.1.100
MQTT_CLIENTID=emoncmsdocker
MQTT_USER=emonpi
MQTT_PASSWORD=emonpimqtt2016
MQTT_BASETOPIC=emon
MQTT_PORT=1883

docker-compose.yml does not contain the port for the container and host

but docker-compose.prod.yml and docker-compose.override.yml does

should i use docker-compose.override.yml ?

so i’m experimenting a bit

this is my composer file:

# Base docker compose, added to by docker-compose.override or docker-compose.prod. See Readme.md

version: '2'

services:
  # PHP & apache container using offical Docker PHP iamge
  web:
    ports:
    # Expose Emoncms to the world on port 80
    - 8080:80
    # If pre-built image from docker hub exists then use that (docker pull openenergymonitor/emoncms:latest) if not Buildcontainer see Dockerflile
    image: openenergymonitor/emoncms:latest
    build: web/.
    volumes:
      # mount docker volumes persistant inside docker container
      - emon-phpfina:/var/opt/emoncms/phpfina
      - emon-phptimeseries:/var/opt/emoncms/phptimeseries
    links:
      # Link to MYSQL DB (see below)
      - db
      - redis

  # MYSQL Database
  db:
    # Official MYSQL docker image
    image: mariadb:latest
    environment:
      - "MYSQL_HOST=localhost"
      - "MARIADB_AUTO_UPGRADE=1"
      - "MARIADB_INITDB_SKIP_TZINFO=1"

      - "MYSQL_PORT=3306"
      - "MYSQL_DATABASE=emoncms"
      - "MYSQL_USER=emoncms"
      - "MYSQL_PASSWORD=***"


    volumes:
      - emon-db-data:/var/lib/mysql
    logging:
      driver: json-file
      options:
        max-size: "10m"

  redis:
    # Official redis image
    image: redis:latest
    environment:
    - "REDIS_ENABLED=false"
    - "REDIS_HOST=redis"
    - "REDIS_PORT=6379"
    # At the moment Docker doesn't honour the REDIS_AUTH variable, so it will always be passwordless
    # REDIS_AUTH=
    - "REDIS_PREFIX='emoncms'"
    volumes:
      - emon-redis-data:/data
    logging:
      driver: json-file
      options:
        max-size: "10m"

  # Consider including mosquitto broker service
  # Needs to be running elsewhere otherwise
  # but maybe thats best.. 
  
  mqtt:
    image: eclipse-mosquitto:latest
    environment:
    - "MQTT_ENABLED=false"
    - "MQTT_HOST=IP-ADDRESS-OF-MQTT-SERVER"
    - "MQTT_CLIENTID=emoncmsmqtt"
    - "MQTT_USER=emonpi"
    - "MQTT_PASSWORD=emonpimqtt2016"
    - "MQTT_BASETOPIC=emon"
    - "MQTT_PORT=1883"
    build: mqtt/.
    restart: always
    

volumes:
  emon-phpfiwa:
    driver: local
  emon-phpfina:
    driver: local
  emon-phptimeseries:
    driver: local
  emon-db-data:
    driver: local
  emon-redis-data:
    driver: local

now i just get a connection refused

after a bit the db container stops and i get

Error: environment var 'MYSQL_HOST' not defined

Error: environment var 'MYSQL_DATABASE' not defined

Error: environment var 'MYSQL_USER' not defined

Error: environment var 'MYSQL_PASSWORD' not defined

Error: environment var 'MYSQL_PORT' not defined

Error: environment var 'REDIS_ENABLED' not defined

Error: environment var 'REDIS_HOST' not defined

Error: environment var 'REDIS_PORT' not defined

Error: environment var 'REDIS_PREFIX' not defined

Error: environment var 'MQTT_ENABLED' not defined

Error: environment var 'MQTT_HOST' not defined

Error: environment var 'MQTT_CLIENTID' not defined

Error: environment var 'MQTT_USER' not defined

Error: environment var 'MQTT_PASSWORD' not defined

Error: environment var 'MQTT_BASETOPIC' not defined

Error: environment var 'MQTT_PORT' not defined

Error: environment var 'PHPFINA_DIR' not defined

Error: environment var 'PHPTIMESERIES_DIR' not defined


Fatal error: Uncaught TypeError: Redis::connect(): Argument #2 ($port) must be of type int, string given in /var/www/emoncms/index.php:39 Stack trace: #0 /var/www/emoncms/index.php(39): Redis->connect('{{REDIS_HOST}}', '{{REDIS_PORT}}') #1 {main} thrown in /var/www/emoncms/index.php on line 39

logs for the db container:

2023-05-10 15:17:53+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.11.2+maria~ubu2204 started.

2023-05-10 15:19:44+00:00 [Note] [Entrypoint]: Switching to dedicated user ‘mysql’

2023-05-10 15:19:44+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.11.2+maria~ubu2204 started.

2023-05-10 15:19:45+00:00 [ERROR] [Entrypoint]: Database is uninitialized and password option is not specified

You need to specify one of MARIADB_ROOT_PASSWORD, MARIADB_ROOT_PASSWORD_HASH, MARIADB_ALLOW_EMPTY_ROOT_PASSWORD and MARIADB_RANDOM_ROOT_PASSWORD

put in a root password

# Base docker compose, added to by docker-compose.override or docker-compose.prod. See Readme.md

version: '2'

services:
  # PHP & apache container using offical Docker PHP iamge
  web:
    ports:
    # Expose Emoncms to the world on port 80
    - 8080:80
    # If pre-built image from docker hub exists then use that (docker pull openenergymonitor/emoncms:latest) if not Buildcontainer see Dockerflile
    image: openenergymonitor/emoncms:latest
    build: web/.
    volumes:
      # mount docker volumes persistant inside docker container
      - emon-phpfina:/var/opt/emoncms/phpfina
      - emon-phptimeseries:/var/opt/emoncms/phptimeseries
    links:
      # Link to MYSQL DB (see below)
      - db
      - redis

  # MYSQL Database
  db:
    # Official MYSQL docker image
    image: mariadb:latest
    environment:
      - "MYSQL_HOST=localhost"
      - "MARIADB_AUTO_UPGRADE=1"
      - "MARIADB_INITDB_SKIP_TZINFO=1"
      - "MARIADB_ROOT_PASSWORD=****"
      - "MYSQL_PORT=3306"
      - "MYSQL_DATABASE=emoncms"
      - "MYSQL_USER=emoncms"
      - "MYSQL_PASSWORD=****"


    volumes:
      - emon-db-data:/var/lib/mysql
    logging:
      driver: json-file
      options:
        max-size: "10m"

  redis:
    # Official redis image
    image: redis:latest
    environment:
    - "REDIS_ENABLED=false"
    - "REDIS_HOST=redis"
    - "REDIS_PORT=6379"
    # At the moment Docker doesn't honour the REDIS_AUTH variable, so it will always be passwordless
    # REDIS_AUTH=
    - "REDIS_PREFIX='emoncms'"
    volumes:
      - emon-redis-data:/data
    logging:
      driver: json-file
      options:
        max-size: "10m"

  # Consider including mosquitto broker service
  # Needs to be running elsewhere otherwise
  # but maybe thats best.. 
  
  mqtt:
    image: eclipse-mosquitto:latest
    environment:
    - "MQTT_ENABLED=false"
    - "MQTT_HOST=IP-ADDRESS-OF-MQTT-SERVER"
    - "MQTT_CLIENTID=emoncmsmqtt"
    - "MQTT_USER=emonpi"
    - "MQTT_PASSWORD=emonpimqtt2016"
    - "MQTT_BASETOPIC=emon"
    - "MQTT_PORT=1883"
    build: mqtt/.
    restart: always
    

volumes:
  emon-phpfiwa:
    driver: local
  emon-phpfina:
    driver: local
  emon-phptimeseries:
    driver: local
  emon-db-data:
    driver: local
  emon-redis-data:
    driver: local

errors are now

Error: environment var 'MYSQL_HOST' not defined

Error: environment var 'MYSQL_DATABASE' not defined

Error: environment var 'MYSQL_USER' not defined

Error: environment var 'MYSQL_PASSWORD' not defined

Error: environment var 'MYSQL_PORT' not defined

Error: environment var 'REDIS_ENABLED' not defined

Error: environment var 'REDIS_HOST' not defined

Error: environment var 'REDIS_PORT' not defined

Error: environment var 'REDIS_PREFIX' not defined

Error: environment var 'MQTT_ENABLED' not defined

Error: environment var 'MQTT_HOST' not defined

Error: environment var 'MQTT_CLIENTID' not defined

Error: environment var 'MQTT_USER' not defined

Error: environment var 'MQTT_PASSWORD' not defined

Error: environment var 'MQTT_BASETOPIC' not defined

Error: environment var 'MQTT_PORT' not defined

Error: environment var 'PHPFINA_DIR' not defined

Error: environment var 'PHPTIMESERIES_DIR' not defined

**Fatal error** : Uncaught TypeError: Redis::connect(): Argument #2 ($port) must be of type int, string given in /var/www/emoncms/index.php:39 Stack trace: #0 /var/www/emoncms/index.php(39): Redis->connect('{{REDIS_HOST}}', '{{REDIS_PORT}}') #1 {main} thrown in **/var/www/emoncms/index.php** on line **39**