# Modbus trouble with Docker

**URL:** <https://discourse.nodered.org/t/modbus-trouble-with-docker/71868>\
**Category:** Industrial\
**Tags:** modbus\
**Created:** [8 December 2022 14:22 UTC](https://discourse.nodered.org/t/modbus-trouble-with-docker/71868 "2022-12-08T14:22:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Josov](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/josov/32/6228_2.png) [@Josov](https://discourse.nodered.org/u/Josov)\
**Post date:** [8 December 2022 14:22 UTC](https://discourse.nodered.org/t/modbus-trouble-with-docker/71868/1 "2022-12-08T14:22:31Z")

</div>

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:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/1/b109ba0e673af8ec2080934e0c119ca373e90b3f.png)

No flows  
No extra nodes installed, just a clean system

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/1/d1ba32ce78c4d647d53bb8f23b38f06064ac8f69.jpeg)

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/a/6a331fd6d5569cb1b6ee3c2e8329e2640530ec52.png)

I tried using serialport@0.15.0, no results

Any ideas welcome!

---

<div class="post-metadata">

**Author:** ![Mikka20](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mikka20/32/75241_2.png) [@Mikka20](https://discourse.nodered.org/u/Mikka20)\
**Post date:** [30 January 2023 10:26 UTC](https://discourse.nodered.org/t/modbus-trouble-with-docker/71868/2 "2023-01-30T10:26:31Z")

</div>

Hi [Josov](https://discourse.nodered.org/u/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

---

<div class="post-metadata">

**Author:** ![Josov](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/josov/32/6228_2.png) [@Josov](https://discourse.nodered.org/u/Josov)\
**Post date:** [30 January 2023 12:50 UTC](https://discourse.nodered.org/t/modbus-trouble-with-docker/71868/3 "2023-01-30T12:50:15Z")

</div>

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:

```auto
# 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.

```auto
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

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [30 January 2023 19:18 UTC](https://discourse.nodered.org/t/modbus-trouble-with-docker/71868/4 "2023-01-30T19:18:49Z")

</div>

Nice - thanks for that.

---

<div class="post-metadata">

**Author:** ![Mikka20](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mikka20/32/75241_2.png) [@Mikka20](https://discourse.nodered.org/u/Mikka20)\
**Post date:** [30 January 2023 20:32 UTC](https://discourse.nodered.org/t/modbus-trouble-with-docker/71868/5 "2023-01-30T20:32:20Z")

</div>

Hi Jos,

thanks for your quick reply. 👍  
I will try the days and hopefully report with success.  
In the meantime i have created a [Bug report](https://github.com/node-red/node-red/issues/4034). Let's see if one of the developers can help.

Greetings  
Mikka

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [31 March 2023 20:32 UTC](https://discourse.nodered.org/t/modbus-trouble-with-docker/71868/6 "2023-03-31T20:32:35Z")

</div>

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