In this tutorial, we will show you how to get Node-RED up and running using Docker easily.
Node-RED is an incredibly powerful yet easy-to-use visual programming tool. With its flow-based approach and drag-and-drop nodes, setting up automation is incredibly simple.
If there aren’t nodes available for what you want to do, Node-RED even enables you to use your own JavaScript functions to handle the workflow. However, before you write your own scripts, you should check out the Node-RED library.
There is a huge number of advantages to using Node-RED. For example, if you are using Home Assistant, this tool can be used to automate your smart home easily. However, if you want to use the Docker version of Node-RED with the Docker version of Home Assistant, you must ensure they are a member of the same network. The easiest way to achieve this is to set up Node-RED in the same Compose file.
Node-RED is also perfect to combine with an MQTT server and a tool like Zigbee2MQTT. Node-RED can react to your MQTT events and perform actions depending on the message received.
Best of all, Node-RED is surprisingly easy to get up and running, especially when using Docker. Thanks to the Node-RED team officially providing containers for most architectures, you can follow this tutorial on all sorts of devices, including a Raspberry Pi.
Installing and Running Node-RED using a Docker Container
Over the following steps, we will walk you through the whole process of setting up Node-RED using Docker.
To make this setup process even easier, we will actually be using a Docker Compose file. These files make managing containers such as Node-RED really simple.
Preparing your System
1. Before you continue with this tutorial, you must ensure that you have Docker installed on your machine.
If you have never installed Docker before, we highly recommend our installation guide.
https://pimylifeup.com/linux-docker-install/
2. Once you have Docker installed, we can use the mkdir command to create a folder to store Node-RED’s Compose file and its data.
We choose to use “/opt/stacks/
” as the base for our container stacks as it gives us one place we can quickly go to. Also, it works with software like Dockge straight out of the box.
sudo mkdir -p /opt/stacks/nodered
3. Once created, move into the directory we just created so we can begin to set up the Node-RED Docker container.
cd /opt/stacks/nodered
Writing a Docker Compose File for Node-RED
4. At this point, we can move on to writing the Docker Compose file that will set up and manage our Node-RED container.
You can begin writing this file by using the following command in the terminal. We are using Nano, but you can use whichever text editor you prefer.
sudo nano compose.yaml
5. Within this file, fill out the following lines. With these lines, we will be setting up the Node-RED container. We will expose the ports 1880
, which this service uses for its web interface.
We then create a volume mount so the configuration files and Node-RED database aren’t lost every time the container restarts.
To make hooking into the Node-RED Docker container easier, we then create a named network called “node-red-net
“. You will want your other containers that you want access to Node-RED to be a member of this network.
Finally, we specify some environment variables that you must fill out. In this case there is only actually the one.
<TIMEZONE>
: Replace this placeholder with your time zone using the TZ Identifier format. You can find a list of these on Wikipedia.
An example of a valid value for this would be “Australia/Hobart
“.
services:
nodered:
container_name: nodered
image: nodered/node-red
ports:
- 1880:1880
volumes:
- node-red-data:/data
networks:
- node-red-net
environment:
- TZ=<TIMEZONE>
restart: unless-stopped
volumes:
node-red-data:
networks:
node-red-net:
6. After you have finished writing this Docker file, save and quit by pressing CTRL + X, Y, and then ENTER.
Starting up the Node-RED Docker Container
7. All we need to do now to start up the Node-RED Docker container is to use the following command within the terminal.
This command will download the Node-RED image and start it up using the details we set within the Compose file. Once started, the container will continue to run until it has been stopped. This means it will also be automatically started when your device reboots.
docker compose up -d
Accessing the Web Interface
8. With the Node-RED container up and running, you will want to access the web interface.
If you don’t know the IP address of your machine, you can often get it by using the hostname command within the terminal.
hostname -I
9. Once you know the IP address of your machine, go to the following address in your favorite web browser. Ensure that you swap “<IPADDRESS>
” your machine’s IP.
You will notice that we must also specify the port “1880
” with this URL. This is because the Node-RED Docker container we set up is configured to show the web interface through this port.
http://<IPADRRESS>:1880
10. Upon going to this URL, you will be greeted by the Node-RED interface. You can begin to use this visual scripting to create your automation flows.
Updating to the Latest Version of Node-RED
One of the key advantages of using Docker to run Node-RED is that it makes the update process very simple. This is especially true if you use a Compose file like we did in this guide.
These next three steps will have you running the latest release of Node-RED in no time.
1. The first step of this update process is to change to the same directory where you wrote the Compose file.
Assuming you have followed our installation guide, you should be able to swap to the correct place by using the command below.
cd /opt/stacks/nodered
2. Once you are in the correct place, you can use the following command to download the latest version of the Node-RED Docker container to your system.
While this command downloads the latest release of Node-RED, it won’t update your existing service.
docker compose pull
3. To get Docker to update your already running container, you only need to use the following command.
After running this, Docker will detect a new version of the Node-RED container has been downloaded and restart your existing container to use the new release.
docker compose up -d
Conclusion
If you have got to this point in the tutorial, you should have hopefully gotten Node-RED up and running on your machine.
As you would have seen, Docker is one of the easiest ways to get Node-RED running. On top of being easy to run, it is also effortless to update. You don’t have to worry about operating system changes breaking the automation platform, as everything it requires is kept within its container.
Please feel free to post a comment below if you have run into any issues with using the Node-RED Docker container.
If you liked this tutorial, we recommend taking some time to check out our many other Docker guides.