Reading data from file inside of docker container

I’m developing a small plugin that lets me read some data from a file I mount inside my docker container.

In the plugin I basically just do:

fs.readFileSync('/etc/files/fileIwant', 'utf-8'))

And I’ve tried many different variations, using __dirname, absolute paths, relative ones etc. And yet I still only get an error similar to:

cannot read file from /data/node_modules/etc/files/fileIWant

I’m using the default node-red docker image.

I’m very confused what is going on and why I cannot read files from the /etc/files folder.
Is there something with node-red that is makes it so I cannot read from outside of the node_modules folder? Is it because of docker? I can see the files are in etc/files so it’s not like they aren’t there.

That’s what Docker does - it separates the container from the host system. So while there will be a “/etc” folder, it’s often not mapped to the same folder on the host - and this is the case with Node Red. You would have to place the file in a folder that the Node Red container can see, as listed below. For example if you store a file in “/mnt/data/supervisor/share” on the host, it will appear in “/share” to Node Red.

Host/volume Path in container
/mnt/data/supervisor/addons/data/a0d7b954_nodered /data
/mnt/data/supervisor/homeassistant /config
/mnt/data/supervisor/ssl /ssl
/mnt/data/supervisor/share /share
/mnt/data/supervisor/media /media
/dev /dev

As you can see, “/etc” is not mapped and so it will only be visible inside the container.

Thanks for the input michaelblight. The interesting part is that if I use something like the node function node and I do the same thing:

const data = fs.readFileSync('/etc/files/fileIwant')
msg.data = data;

return msg;

I get the files I want.

So the builtin nodered function seems to access the dir.