Docker - Node-RED Container Setup with Authentication and Home Assistant Nodes


Here I describe my setup of the Node-RED docker container.

I run this Docker container on a Ubuntu VM that runs via [[ Proxmox VE ]]. I perform the following on the CLI.

Docker pull command:

docker pull nodered/node-red

Within my home folder I have created a Docker folder where I create a subfolder for each container:

cd ~
mkdir -p docker/nodered
cd docker/nodered

Also create a folder where the Node-RED data can be stored:

mkdir data

I use the Nano text editor to create a shell script:

sudo nano nodered_run.sh

With this shell script we are going to create the container. Copy the following into nodered_run.sh:

docker run -d \
 --hostname=nodered \
 --name=nodered \
 --net=host \
 -v $PWD/data:/data \
 -e TZ="Europe/Amsterdam" \
 -e "NODE_RED_CREDENTIAL_SECRET=KEY" \
 --restart=unless-stopped \
 --cap-add=NET_ADMIN \
 nodered/node-red

Make sure port 1880 is available. Check this with netstat.

If necessary, adjust the following:

-v $PWD/data:/data
Choose the location for the Node-RED data. In this example it is the data map we created

-e “TZ=Europe/Amsterdam”
Pick the right timezone

-e “NODE_RED_CREDENTIAL_SECRET=KEY”
(Optional) Replace KEY with your own key you can specify in settings.js. Otherwise a key will be automatically generated

Exit Nano (CTRL-X) and save the changes.

Now create the container:

sudo sh nodered_run.sh

Check if the container is running properly.

Enable Authentication (optional)

Because I use Home Assistant nodes within Node-RED but also, for example, an SSH node, I have set up authentication to make it a bit more secure.

Make sure the container is running and generate a hash for the password you want to use:

docker exec -it nodered npx node-red admin hash-pw

Enter the password you want to use for Node-RED and copy the hash to memory.

Now adjust the following in the settings.js:

docker stop nodered
cd data #nodered/data map
sudo nano settings.js

And uncomment adminAuth. Then it will look like this:

    adminAuth: {
        type: "credentials",
        users: [{
            username: "USER",
            password: "HASH",
            permissions: "*"
        }]
    },

Adjust the following:

username: USER
Choose your own username. I chose for example admin

password: “HASH”
Replace HASH with your own hash you generated earlier. Copy the hash from memory

permissions: "*"
(Optional) Change the permissions if needed

Exit Nano (CTRL-X) and save the changes. Now you can start the container again:

docker start nodered


Install Additional Nodes (optional)

The container uses the directory /data as the user configuration directory. To add additional nodes you can open shell into the container and run the appropriate npm install commands. Here are a few examples of nodes I always install:

# Open a shell in the container  
docker exec -it nodered /bin/bash
# Once inside the container, npm install the nodes in /data  
cd /
cd data
npm install node-red-node-wol
npm install node-red-contrib-bigssh
npm install node-red-contrib-home-assistant-websocket
exit

npm install node-red-node-wol
(Optional) A node to send Wake-On-LAN (WOL) magic packets

npm install node-red-contrib-bigssh
(Optional) Big SSH is an input node for node-red to execute a command over SSH to a remote host

npm install node-red-contrib-bigssh
(Optional) Various nodes to assist in setting up automation using Node-RED communicating with Docker - Home Assistant Container Setup with MariaDB and InfluxDB 2.x

Now restart the Docker container:

docker restart nodered

Using Node-RED

Node-RED can now be accessed via the following URL:

http://<IP DOCKER HOST>:1880/

See also my notes about updating containers with Portainer or via the CLI. With Synology’s Docker Application, updating a container is also very easy.


Read other notes

Comments

    No comments found for this note.

    Join the discussion for this note on this ticket. Comments appear on this page instantly.

    Tags


    Notes mentioning this note


    Notes Graph