IMD SolutionComputing LibraryShop main store

Troubleshooting

Expose a serial port to Node-RED in a Docker container

Edge computing and IIoT Published 5 min read

Short answer

A serial device is reachable in a Node-RED Docker container only when it is mapped under devices at the same host path and the container process belongs to the group that owns that device on the host, usually dialout. Mapping without the group leaves the port visible but unopenable.

On this page
  1. Why the port is visible but not openable
  2. The Compose configuration that works
  3. Verify in order: node, permission, then protocol
  4. When the tty name is not stable
  5. Common variants
  6. Questions asked

Node-RED in a Docker container cannot open a serial port unless you do two things: map the host device into the container under the same path with the service's devices entry, and give the container process membership in the group that owns that device on the host, which on most Linux systems is dialout. If the port is missing inside the container, the mapping is wrong. If the port is visible but the Modbus node reports a permission error, the group membership is missing. Do not diagnose Modbus RTU settings until the container can open the port cleanly.

Why the port is visible but not openable #

The devices entry only makes the device node appear inside the container; it does not change permissions. On the host, a USB serial adapter is typically owned by a group such as dialout, and the process inside the container runs as a user who is not a member of that group. The result is exactly the symptom reported with Arduino adapters on /dev/ttyACM0 and USB sticks on /dev/ttyUSB0: the node exists, the serial node finds it, and the open fails with a permission error.

The fix is group_add in the service definition, which grants the container's process supplemental membership in a host group by name. Note that adding a user to a group inside the image build does not reliably cover this case; group_add at the service level does, and it is the documented Compose mechanism for it.

The Compose configuration that works #

Add the device mapping and the group to your Node-RED service, then recreate the container so both take effect. For an Arduino on /dev/ttyACM0:

version: "3"
services:
  node-red:
    image: nodered/node-red:latest
    container_name: secure_noderedx
    ports:
      - "1880:1880"
    volumes:
      - volume_server_1:/data
    devices:
      - /dev/ttyACM0:/dev/ttyACM0
    group_add:
      - dialout

Three details matter:

  • Map the device at the same path it has on the host, in the form host path:container path. Mapping to a different name invites confusion when the serial node looks for a node that the host never creates.
  • Verify the actual host group instead of assuming dialout. Run ls -l /dev/ttyACM0 on the host; whatever group owns the device is the name that belongs under group_add. On Debian-based hosts this is almost always dialout.
  • docker compose up -d --force-recreate (or down and up) is required. Changing Compose does nothing to a running container.

If you run rootless Docker, the same mapping applies but group name resolution differs between the host and the user namespace; if dialout by name does not grant access, pass the numeric group ID from the host instead.

Verify in order: node, permission, then protocol #

Work through this list before touching Modbus settings:

  • On the host, confirm the adapter is present: ls /dev/ttyACM0 (or /dev/ttyUSB0). If it is not there, that is a host or cable problem, not a container problem.
  • Confirm the group: ls -l /dev/ttyACM0 shows the owning group. Put that exact name under group_add.
  • Recreate the container so the mapping and the group apply.
  • Inside the container, confirm the node is visible and readable: docker exec -it secure_noderedx ls -l /dev/ttyACM0. A container user that lacks permission still sees the node in the listing, so also attempt the open from Node-RED itself.
  • In Node-RED, configure the Modbus serial node for /dev/ttyACM0 and try to connect. If the port opens with no permission error, the container side is done.

The split is the whole diagnosis: absent node means fix devices; present node that fails to open means fix group_add. Only after the open succeeds do baud rate, parity, stop bits and slave address become the next question, and those must match the attached device's firmware; the container configuration has no effect on them. For the wider picture of moving that Modbus RTU data once the port is live, MQTT to Modbus TCP with Node-RED on an edge gateway covers the path from serial reads to broker topics, and running Modbus TCP from Node-RED inside a container brings its own host-networking rules.

When the tty name is not stable #

USB enumeration order is not guaranteed. A stick that appears as /dev/ttyUSB0 today can come back as /dev/ttyUSB1 after a replug or a reboot, and the container then loses the device. Use the stable symlink Linux creates for it: run ls /dev/serial/by-id/ on the host and map that full path into the container instead of the tty name, keeping the group_add entry. The same devices syntax applies, only with the by-id path on both sides.

One safety note: a container that can open a serial port can write to whatever hangs on it, including drives and actuators on a live line. Give the mapping only to the container that needs it, and keep control-path devices off shared or development containers.

Common variants #

  • Windows hosts. Docker Desktop on Windows does not pass through COM ports under the Linux devices entry the way a Linux host does; expose the adapter through a TCP-to-serial bridge on the host instead, and point the Node-RED Modbus node at that TCP endpoint.
  • Adapter works only sometimes. Intermittent access is usually a second process on the host holding the port, or a replug that changed the tty number; check for another serial client and move to the by-id mapping.
  • Permission denied inside the container after everything above. Confirm the container was actually recreated, and check that the group name you added is the one shown in the device's host ownership, not a similarly named group from an image layer.

Questions asked

Why can Node-RED see the serial device in the container but not open it?

The device node is present because of the devices mapping, but the container user is not a member of the group that owns it on the host. Check the group on the host with ls -l on the device, then add that group name under group_add in the service and recreate the container. Mapping alone never grants read and write permission.

Should the device be mapped to a different path inside the container?

No. Map the device at the same path it has on the host, for example /dev/ttyACM0:/dev/ttyACM0. Mapping to a different path can work, but Node-RED's serial nodes then look for a node name the host never produces, and a by-id path is safer when USB enumeration order changes. Same-path mapping is the simplest reliable choice.

Does exposing the serial device configure Modbus RTU?

No. The devices entry and the group membership only let the container open the port. Baud rate, parity, stop bits and slave address are configured in the Node-RED Modbus serial node and must match the attached device. Configure those only after the port opens without a permission error.

What changes when the adapter is a USB stick that replugs?

USB enumeration can change the ttyUSB or ttyACM number after a replug or reboot. Use the device's stable by-id symlink under devices instead of the tty name, verify the by-id path with ls /dev/serial/by-id on the host, and keep the group_add entry for the group that owns it.

Keep reading

  • Troubleshooting

    Fix Node-RED Docker x509 Certificate Expired on an Edge PC

    The error x509: certificate has expired or is not yet valid means Docker reached the registry over TLS but the controller clock falls outside the certificate's validity dates. Set the correct date and an NTP server, confirm the controller shows the right UTC time, and re-run the same docker run command — the pull verifies on the next connection. Change nothing else first.

    Edge computing and IIoT

  • Troubleshooting

    Node-RED MQTT stuck on connecting inside a Docker container

    A Node-RED MQTT node stuck on connecting means no session was ever established: the transport connection to the server address and port never completed, or the broker declined the client. Test name resolution and routing from inside the container, then set the server to the broker's IP address and the port of its active listener. The controller's own IP works only when a broker actually listens there.

    Edge computing and IIoT

  • How-to

    Auto restart Node-RED in Docker after exit code 255

    Run the container with `--restart unless-stopped` so Docker restarts Node-RED on its own whenever the process exits with code 255, while a deliberate stop still holds. Then set the console log level in `/data/settings.js` to `debug` until one failure is captured, because exit 255 names an abnormal end, not the fault.

    Edge computing and IIoT