NodeRed with Docker desktop on a Mac - not finding settings.js

So I don't know how to fix that. I want my project to run in a container for my local dev doings.

I got my already working project as the base folder. including the settings.js and the flows.json. so far so good.

Now i created a docker-compose.yml containing a very basic setup:

################################################################################
# Node-RED Stack or Compose
################################################################################
# docker stack deploy node-red --compose-file docker-compose-node-red.yml
# docker-compose -f docker-compose-node-red.yml -p myNoderedProject up
################################################################################
#version: "3.7"

services:
  node-red:
    image: nodered/node-red:latest
    environment:
      - TZ=Europe/Amsterdam
    ports:
      - "1880:1880"
    networks:
      - node-red-net
    volumes:
#      - ./settings.js:/data/settings.js
      - .:/data


networks:
  node-red-net:

When I do a "docker-compose start" in the directory folder I simply get

username@MBPM4KG $: docker-compose up
[+] Running 1/1
 ✔ Container rennstalllegende-node-red-1  Created                                                                                                                                                                              0.0s 
Attaching to node-red-1
node-red-1  | Error loading settings file: /data/settings.js
node-red-1 exited with code 1

The settings.js exists, it looks fine so far?
Anybody an idea?

You could check that Docker can actually access the directory:

does your settings.js reside in the same directory as the docker-compose file? Because . means the current directory and normally the settings.js and the docker-compose.yaml do not reside in the same directory.

thx for the quick responese. So it is my lack of docker knowledge.

To answer the question "permissions"

-> Yes, the folder is in the Documents folder of my Mac user and the /Users is added by Docker Desktop by default. So this works.

What I've tried since your answer:

In my root of the project I've created a new folder "data" where all the NodeRed stuff is moved. flows.json, settings.js and everything else…
It looks now like this

/
  docker-compose.yml
  ReadMe.md
  /data
    settings.js
    flows.json
    ...

The docker.compose.yml looks now like this:

services:
  node-red:
    image: nodered/node-red:latest
    environment:
      - TZ=Europe/Amsterdam
    ports:
      - "1880:1880"
    networks:
      - node-red-net
    volumes:
#      - ./settings.js:/data/settings.js
      - ./data:/data


networks:
  node-red-net:

Which results in:

  • starting up
  • creating a new settings.js in the project-root
  • not finding a flows.json and start blank

you haven't made any changes to the settings.js specifically:

/** The file containing the flows. If not set, defaults to flows_<hostname>.json **/
flowFile: 'flows.json',

which is at the top of the settings.js file.

nor this:

    /** By default, all user data is stored in a directory called `.node-red` under
     * the user's home directory. To use a different location, the following
     * property can be used
     */
    //userDir: '/home/nol/.node-red/',

the userDir must be commented out in the settings.js or set to /data

Since the Dockerfile for the image you're using has an entrypoint.sh which determines how node red is started:

#!/bin/bash

trap stop SIGINT SIGTERM

function stop() {
	kill $CHILD_PID
	wait $CHILD_PID
}

/usr/local/bin/node $NODE_OPTIONS node_modules/node-red/red.js --userDir /data $FLOWS "${@}" &

CHILD_PID="$!"

wait "${CHILD_PID}"

The userDir is set to /data in the docker image so that's why the ./<local dir>:/data line is important in the docker compose file.

The $FLOWS determines which flows.json file to use, this defaults to "flows.json" because of line 33 (the end of the line) in the Dockerfile:

ENV NODE_RED_VERSION=v4.0.9 NODE_PATH=/usr/src/node-red/node_modules:/data/node_modules PATH=/usr/src/node-red/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin FLOWS=flows.json

I assume you don't set the environment variable $FLOWS to something else?

I think all of this is also discussed under managing user data.

I solved the problem. The docker setup was right, everything was ok. The only thing in my settings.js was, that I required playwright(already installed locally) which was not installed on the new NodeRed docker instance… therefore the file was not useable.
uncommenting the line helped and everything worked again.

thx for the time you invested in answering.