Modbus trouble with Docker

I have trouble to get Modbus working inside a Docker container.
I am using RPI OS 64-bit latest version. Image nodered/node-red:latest
Node.js v16.16.0
Linux 5.15.76-v8+ arm64 LE

Here is how I start the container:

docker run -it -p 1880:1880 -v /home/pi/docker/nodered/node_red_data:/data -v /dev:/dev --group-add dialout --name nodered --device=/dev/ttyACM0 nodered/node-red

The serial Modbus device is:

No flows
No extra nodes installed, just a clean system

I install node-red-contrib-modbus and configure a modbus configuration node, deploy and the result is exit Node-RED with this error:

I tried using serialport@0.15.0, no results

Any ideas welcome!

Hi Josov,

I have the same problem.
With the command
"docker run -it -p 1880:1880 -v node_red_data:/data --name node-red --device=/dev/ttyUSB1 nodered/node-red"
docker starts.

With the command
"docker run -it -p 1880:1880 -v node_red_data:/data --name node-red --group-add dialout --device=/dev/ttyUSB1 nodered/node-red" or "docker run -it -u node-red:dialout -p 1880:1880 -v node_red_data:/data --name node-red --device=/dev/ttyUSB1 nodered/node-red"
i get a segfault:
30 Jan 09:51:59 - [info] Started flows
./entrypoint.sh: line 14: 7 Segmentation fault (core dumped) /usr/local/bin/node $NODEOPTIONS node_modules/node-red/red.js --userDir /data $FLOWS

I have installed debian + node-red on the same docker host. in this constellation everything works.

Did you get any further with this problem?

Thx,
Mikka

Hi Mikka,

Nice to hear from you. In the mean time I solved the problem. However I am using docker-compose to install node-red but this is not essential.

Maybe start as follows:
$ docker exec -it node-red bash

Check your ports using:
# ls -l /dev/serial/by-id

Is your port there?
If yes, continue with:
# whoami

If your port is not there: it worked out well using ‘root’ as node-red user. The --group-add dialout did not make the difference. An other thing I had to do to make it work is the following. From the palette I installed node-red-node-serialport (although I did not need it), then go back in the docker container with:

$ docker exec -it node-red bash

And, as your data directory is /data do as follows at the bash prompt:

# cd /data/node_modules/node-red-node-serialport
# npm rebuild --build-from-source
# cd ../serialport
# npm rebuild --build-from-source
# cd ../node-red-contrib-modbus
# npm rebuild --build-from-source

This with user=root did the job.

I am using docker-compose to install node-red and I set the user to root. I am passing the parameters I need in node-red through environment variables, all collected in one file. Here you find a few of them under environment.

node-red:
container_name: nodered
image: nodered/node-red:latest
restart: unless-stopped
user: root
environment:
- MODBUSPORT=$MODBUS_SERIAL_PORT
- P1SERIALPORT=$P1_SERIAL_PORT
network_mode: host
expose:
- "80"
privileged: true
depends_on:
- "mariadb"
- "mqtt"
- "zigbee2mqtt"
volumes:
- /home/pi/docker/nodered/node_red_data:/data
- /home/pi/docker/backup:/backup
- /home/pi/docker/zigbee2mqtt/data:/z2mdata
- /dev:/dev
- /home/pi/.acme.sh/$MYDOMAIN:/certs

Success!

Jos

1 Like

Nice - thanks for that.

Hi Jos,

thanks for your quick reply. :+1:
I will try the days and hopefully report with success.
In the meantime i have created a Bug report. Let's see if one of the developers can help.

Greetings
Mikka

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.