Skip to content

Node-RED Under Docker

In this section will be detailed how to install Node-RED image under Docker and how to create a service which launches the Node-RED image running under Docker.

Due to space constraints, Docker is only recommended to be installed on eManager Pro.

Node-RED image installation

Node-RED images are publicly available in the Docker Hub container image library. In this example node-red:latest-16-minimal image will be used.

First, create directories in your eManager that we will use to generate the image and give to it the needed permissions:

mkdir -p ~/dockers/node-red/data
chmod 777 ~/dockers/node-red/data

Then, create a docker-compose.yml file in the ~/dockers/node-red/ folder:

nano ~/dockers/node-red/docker-compose.yml

with the following content:

version: "3.0"
services:
  node-red:
    image: nodered/node-red:latest-16-minimal
    container_name: node-red
    environment:
      - TZ=Europe/Madrid
    ports:
      - "1880:1880"
    volumes:
      - ~/dockers/node-red/data:/data

It is strongly recommended to mount the data content of docker images in /data partition. This will make you save space in /dev/root partition.

The above compose file:

  • Pulls the latest-16-minimal Node-RED image
  • Defines a Node-RED container called node-red, which will run in a service called node-red
  • Sets the timezone to Europe/Madrid
  • Maps the container port 1880 to the the host port 1880
  • Persists the /data dir inside the container to the user local ~/dockers/node-red/data directory

We are binding Node-RED under Docker port to the same port which is using node-red service in the eManager. If you want to have both Node-RED's running at the same time you have to change the port of one of them.

It is needed to stop the node-red service which is running natively in the eManager, before the creation of the new container which will run Node-RED under Docker.

systemctl stop node-red

And finally, create the Node-RED container:

cd ~/dockers/node-red/
docker-compose up --no-start

Managing user data

Once you have Node-RED running with Docker, we need to ensure any added nodes or flows are not lost if the container is destroyed. This user data can be persisted by mounting a data directory to a volume outside the container. This can either be done using a bind mount or a named data volume.

Node-RED uses the /data directory inside the container to store user configuration data.

Node-RED under Docker as a service

Once the Node-RED container has been created, a service needs to be created to interact with Node-RED under Docker in a simpler manner.

nano /lib/systemd/system/node-red-docker.service

with the following content:

[Unit]
Description=Node-RED container
After=docker.service
Wants=network-online.target docker.socket
Requires=docker.socket

[Service]
Restart=always
ExecStart=/usr/bin/docker start -a node-red
ExecStop=/usr/bin/docker stop -t 10 node-red

[Install]
WantedBy=multi-user.target

Then, reload the added systemd units files using:

systemctl daemon-reload

You can find more information about how to create a systemd.service here.

Enable Node-RED Docker service

First, disable native node-red service, so it will not be started each time the eManager is powered:

systemctl disable node-red

Then, start node-red-docker service and enable it if you want it to start automatically each time the eManager is powered:

systemctl start node-red-docker
systemctl enable node-red-docker