Michael Hecht
Michael Hecht

Reputation: 2253

Docker Node-Red: Keep installed nodes outside container

I have to install a lot of missing node-red nodes to the container. Keeping the (named) container and running it with docker start works fine.

Now I want to keep the installed nodes in a separate external directory. If I mount /data do an external directory it basically works but doesn't help since the nodes are installed in ~/node_modules. If I try to mount ~/node_modules to an external directory, node-red can't start.

So what can I do to keep the nodes I installed independent of the executed container?

EDIT: Meanwhile I did run the image as follows:

#!/bin/bash
sudo -E docker run -it --rm -p 1893:1880 -p 11893:11880 
  \ -e TZ=Europe/Berlin -e NPM_CONFIG_PREFIX=/data/node_modules/ 
  \ -e NODE_PATH=/usr/src/node-red/node_modules:/data/node_modules:/data/node_modules/lib/node_modules 
  \ --log-driver none --mount type=bind,source="$(pwd)"/data,target=/data 
  \ --name myNodeRed nodered/node-red

but the additional installed nodes, that are in directory /data/node_modules/lib/node_modules are still not visible.

EDIT 2: Meanwhile I tried to keep the container. So it became obvious, that nodes installed using npm install -g are fully ignored.

Upvotes: 0

Views: 780

Answers (1)

hardillb
hardillb

Reputation: 59686

The default user for the Node-RED instance inside the container is not root (as is usual) so you need to make sure any volume you mount on to the /data location is writable by that user. You can do this by passing in the user id to the container to have it match the external user that has write permission to the mount point:

docker run -it --rm -v $(pwd)/data:/data -u $USER -e TZ=Europe/Berlin
 \ -p 1893:1880 -p 11893:11880 --log-driver none
 \ --name myNodeRed nodered/node-red

Node-RED nodes should not be installed with the -g option, you should use the build in Palette Manager or if you really need to use the command line, run npm install <node-name> in the /data directory inside the container (But you will need to restart the container for the newly installed nodes to be picked up, which is again why you should use the Palette Manager)

Upvotes: 2

Related Questions