In this post, we will see how we can run Node-RED using Docker Containers on our Ubuntu Server. Node-RED is a flow-based development tool for visual programming, for wiring together hardware devices, APIs and online services as part of the Internet of Things.

The light-weight runtime is built on Node.js, taking full advantage of its event-driven, non-blocking model. The flows created in Node-RED are stored using JSON which can be easily imported and exported for sharing with others.

There are a lot of installations method available, that you can find in the Getting Started page of Node-RED, but we will use Docker containers to easily deploy the software.

Run Using Docker

To run in Docker headless, (i.e. in the background), run:

docker run -d -p 1880:1880 -v node_red_data:/data --name mynodered nodered/node-red

Docker run options explained:

  • docker run - run this container, initially building locally if necessary
  • -d - run container in background
  • -p 1880:1880 - connect local port 1880 to the exposed internal port 1880
  • -v node_red_data:/data - mount a docker named volume called node_red_data to the container - data directory so any changes made to flows are persisted
  • --name mynodered - give this machine a friendly local name
  • nodered/node-red - the image to base it on - currently Node-RED v1.2.0

The volume node_red_data will be placed under /var/lib/docker/volumes in order to store persisting data for the docker container.

You can then browse to http://ip-server:1880 to get the familiar Node-RED desktop.

Container Shell

Once it is running headless you can use the following command to get access back into the container:

docker exec -it mynodered /bin/bash

Remove Container

If you want to restart the container, you will have a name conflict for the --name mynodered option. In order to reuse the same name, you can first remove the previous container by running:

docker rm mynodered

and then you can run the container again with the same name.

Note, that the node_red_data directory under /var/lib/docker/volumes is not deleted with the docker rm command.

Managing User Data on Host Directory

With the previous command any user data is saved in /var/lib/docker/volumes/node_red_data as a volume. If you want to save your Node-RED user directory inside the container to a host directory outside the container, you can use the command below:

docker run -d -p 1880:1880 -v /home/$USER/.node-red:/data --name mynodered nodered/node-red

where $USER is the user on your system.

This command, save the user data in the home directory of the user in the .node-red directory. To allow access to this host directory, the $USER (default uid=1000) inside the container must have the same uid as the owner of the host directory.

Updating

As the /data is now preserved outside of the container, updating the base container image is now as simple as:

docker pull nodered/node-red
docker stop mynodered
docker rm mynodered
docker run -d -p 1880:1880 -v node_red_data:/data --name mynodered nodered/node-red