Node-RED container with authentication and Home Assistant nodes setup
Introduction
Node-RED is a programming tool. It provides a browser-based editor that makes it easy to wire together flows using the wide range of nodes in the palette that can be deployed to its runtime in a single-click.
Setup
- 
Create the folders needed by the container
Run the following commands inside your home folder:
# Open your terminal applicationcd ~mkdir -p nodered/datacd nodered - 
Create the script needed to run the container
Save the following script as
nodered_run.sh:nodered_run.sh # To create this script use your text editor application, for example Nanodocker run -d \--hostname=nodered \--name=nodered \--net=host \-v $PWD/data:/data \-e "NODE_RED_CREDENTIAL_SECRET=<key>" \-e TZ="Europe/Amsterdam" \--restart=unless-stopped \--cap-add=NET_ADMIN \nodered/node-red# IMPORTANT: Please read the instructions belowInstructions:
- Optional  Replace 
dockerwithpodmanif needed - Optional  Replace 
--net=hostwith ports to pass through if you want to expose ports. Here is described how to check if ports are available. Make sure port1880is available - Optional  Replace 
$PWD/datawith the location of your data if needed. This can be a fileserver mount - Optional  Replace 
<key>with your own key which you can specify insettings.js. Otherwise a key will be automatically generated - Required  Replace 
Europe/Amsterdamwith your own timezone 
 - Optional  Replace 
 - 
Run the script to create the container
Run the following command:
# Open your terminal applicationsudo sh nodered_run.shThe image
nodered/node-redis automatically pulled and the container is created. - 
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 Node-RED container is running and generate a hash for the password you want to use:
# Open your terminal applicationsudo docker exec -it nodered npx node-red admin hash-pwEnter the password you want to use for Node-RED and copy the hash to memory.
Now adjust the following in the
nodered/data/settings.jsfile:nodered/data/settings.js // To edit use your text editor application, for example NanoadminAuth: {type: "credentials",users: [{username: "<username>",password: "<hash>",permissions: "*"}]},// IMPORTANT: Please read the instructions belowInstructions:
- Required  Replace 
<username>with your username,adminfor example - Required  Replace 
<hash>with the hash you generated earlier. Copy the hash from memory - Optional  Replace 
*if needed to change the permissions 
Restart the Node-RED container. Run the following command:
# Open your terminal applicationsudo docker restart nodered - Required  Replace 
 - 
Install additional nodes (optional)
The container uses the
/datadirectory as the user configuration directory. To add additional nodes you can open the shell into the container and run the appropriate npm install commands. Here are a few examples of nodes I always install:# Open your terminal application# Open a shell in the containersudo docker exec -it nodered /bin/bash# Once inside the container, npm install the nodes in /datacd /cd datanpm install node-red-node-wolnpm install node-red-contrib-bigsshnpm install node-red-contrib-home-assistant-websocketexitInstructions:
- Optional  
node-red-node-wolis a node to send Wake-On-LAN (WOL) magic packets - Optional  
node-red-contrib-bigssh(Big SSH) is an input node to execute a command over SSH to a remote host - Optional  
node-red-contrib-home-assistant-websocketare various nodes to assist in setting up automation using Node-RED communicating with Home Assistant 
Restart the Node-RED container. Run the following command:
# Open your terminal applicationsudo docker restart nodered - Optional  
 - 
Check the results
If needed you can check if the container is running properly.
Now you can use Node-RED by opening a web browser and going to:
http://localhost:1880. Replace localhost with the relevant IP address or FQDN if needed, and adjust the port if you changed it earlier. 
No comments found for this note.
Join the discussion for this note on Github. Comments appear on this page instantly.