And from the Docker image notes
Host Directory As Volume (Persistent)
To save your Node-RED user directory inside the container to a host directory outside the container, you can use the command below. But to allow access to this host directory, the node-red user (default uid=1000) inside the container must have the same uid as the owner of the host directory. To override the default uid and gid of the node-red user inside the the container you can use the option --user="<my_host_uid>:<my_host_gid>"
:
$ docker run -it --user="<my_host_uid>:<my_host_gid>" -p 1880:1880 -v <host_directory>:/data --name mynodered nodered/node-red
Example:
- Suppose you are running on a Raspberry PI with a user named 'pi' and group 'pi'.
$ whoami
- With this user create a directory '~/.node-red'.
$ mkdir ~/.node-red
- Verify newly created directory with:
$ ls -al ~/.node-red
This shows that user pi is owner of this directory:
ls -al ~/.node-red
total 8
drwxr-xr-x 2 pi pi 4096 May 7 20:55 .
drwxr-xr-x 8 pi pi 4096 May 7 20:42 ..
- Now we want to have access to this '~/.node-red' directory with the container so that Node-RED can save user data to it. As we know we need to override the default uid (1000) of the node-red user inside the container with the uid of the pi user. For that we need to know the uid of user pi:
$ id pi
- The uid and gid of user pi are:
uid=1000(pi) gid=1000(pi) [...]
- So the final command becomes:
$ docker run -it --user="1000:1000" -p 1880:1880 -v ~/.node-red:/data --name mynodered nodered/node-red