Skip to content

Permissions and Persistence

Cleber Jorge Amaral edited this page Jun 4, 2020 · 4 revisions

Permissions

The user node-red inside the Node-RED Docker container runs the Node-RED application. This user has user id 1000 and belongs to group node-red, which has group id 1000. This is applicable to all Node-RED Docker images.

Persistence

Docker containers are ephemeral, and don’t persist data across runs. Inside the Node-RED Docker container the /data directory is the location, where Node-RED stores all it's user data like settings.js, flows.json, credentials, node_modules, projects, context, libs etc.

It is preferable to persist this data outside the container so that when a container gets upgraded or, re-deployed - Node-RED reloads the /data directory and the new container is up and running with everything restored. The /data directory is owned by the user node-red (1000:1000), and all files and directories are saved with the same user node-red. To do this the node-red user needs read/write permissions to the directory outside the container.

Only UIDs (user ids) and GIDs (group ids) matter. For example names and passwords of users and groups do not need to match or even exist in both host and container.

Setting up persistence

On most Linux system the first user created is often set as uid 1000 - A quick check of your current user can be done by

id $USER

output:

uid=1000(ubuntu) gid=1000(ubuntu) groups=1000(ubuntu)...

In this case creating the host directory with user ubuntu automatically inherits the correct uid and gid from the user. Creating a directory is done by the following command:

mkdir -p /home/ubuntu/node-red/data

The above command creates the node-red directory and its sub-directory data in the home directory of user ubuntu.

Make sure your host directory exists and is owned by a user with 1000:1000.

ls -nal /home/ubuntu/node-red

output example:

drwxrwxr-x 3 1000  100 4096 Oct  2 12:02 .
drwxrwxr-x 3 1000  100 4096 Oct  2 09:25 ..
drwxr-xr-x 3 1000 1000 4096 Oct  2 10:23 data

The last line of this output example shows in the third column the uid 1000 and in the fourth column the gid 1000. If this is not the case then it needs to be set to be owned by the correct user

sudo chown -R 1000:1000 /home/ubuntu/node-red/data

The first column shows the permissions, which means:

  • the owner has read, write and execute permissions
  • the group has read, and execute permissions
  • and public (any one else) has read, execute permissions

Again it should be corrected if necessary

sudo chmod 755 /home/ubuntu/node-red/data

An easy calculator can be found at chmod-calculator.com

Running

Once the data directory has been created and has the correct permissions the container can be started

docker run -it -v /home/ubuntu/node-red/data:/data nodered:node-red:latest