Installing Node-RED using Docker on a Raspberry Pi 5
Installing Node-RED using Docker on a Raspberry Pi 5 with a 64-bit ARM architecture is a straightforward process.
This guide will walk you through the steps to get Node-RED up and running in a Docker container on your Raspberry Pi.
Prerequisites
Raspberry Pi 5 with a 64-bit ARM architecture
Raspberry Pi OS (64-bit) installed on your Raspberry Pi
Docker installed on your Raspberry Pi
Run Node-RED in a Docker Container
Pull the Node-RED Docker image:
docker pull nodered/node-red:latest
Create a named data volume to persist Node-RED data
docker volume create node_red_data
Run the Node-RED container
docker run -it -p 1880:1880 -v node_red_data:/data --name mynodered nodered/node-red
This command does the following:
-it
: Runs the container in interactive mode with a terminal attached.-p
1880:1880
: Maps the container's port 1880 to the host's port 1880.-v
node_red_data:/data
: Mounts the named data volumenode_red_data
to the container's/data
directory.--name mynodered
: Assigns a friendly name to the container.nodered/node-red
: Specifies the Docker image to use.
Access Node-RED in a web browser by opening http://<raspberry-pi-ip>:1880
, replacing <raspberry-pi-ip>
with the IP address of your Raspberry Pi.
Wally's IP Address for Raspberry Pi
Managing the Node-RED Container
To stop the Node-RED container:
docker stop mynodered
To start the Node-RED container:
docker start mynodered
To restart the Node-RED container:
docker restart mynodered
To remove the Node-RED container (the data will persist in the named volume):
docker rm mynodered
To install additional Node-RED nodes, you can access the container's shell
docker exec -it mynodered /bin/bash
Once inside the container, you can use npm to install nodes:
npm install node-red-contrib-example
To customize Node-RED settings, you can create a settings.js
file on the host and mount it into the container:
docker run -it -p 1880:1880 -v node_red_data:/data -v /path/to/settings.js:/data/settings.js --name mynodered nodered/node-red
Replace /path/to/settings.js
with the actual path to your settings.js
file.
To access the host's GPIO pins from within the Node-RED container, you can use the --device
flag to pass the device access through:
docker run -it -p 1880:1880 -v node_red_data:/data --name mynodered --device=/dev/gpiomem nodered/node-red
Note: This requires the node-red-node-pi-gpiod
nodes to be installed and configured to connect to the host's PiGPIOd daemon.
Using Docker Compose (Optional) Docker Compose simplifies the management of containers by allowing you to define and run multi-container applications with a single command.
Create a docker-compose.yml
file with the following content:
version: '3'
services:
node-red:
image: nodered/node-red:latest
container_name: mynodered
restart: unless-stopped
volumes:
- node_red_data:/data
ports:
- "1880:1880"
devices:
- "/dev/gpiomem:/dev/gpiomem"
volumes:
node_red_data:
Save the file and run the following command to start Node-RED
docker compose up -d
The -d
flag runs the containers in detached mode.
To stop the Node-RED container started with Docker Compose
docker-compose down
Conclusion
Running Node-RED in a Docker container on a Raspberry Pi 5 with a 64-bit ARM architecture provides a convenient and reproducible way to deploy and manage Node-RED instances.
Docker allows you to easily update, customise, and scale your Node-RED deployments while keeping your data persisted in named volumes.
With this setup, you can take advantage of the powerful features of Node-RED on your Raspberry Pi, such as building IoT applications, automating tasks, and integrating various services and devices.
Remember to regularly update your Node-RED container to benefit from the latest features, bug fixes, and security patches.
Last updated
Was this helpful?