Troubleshooting
Why GPIO access fails inside a Node-RED IoT Edge module
Short answer
A working port mapping proves only the network path. GPIO fails in the module because the container lacks the device node the GPIO backend opens and a process identity permitted to open it: bind the specific device, such as /dev/gpiomem, and give the Node-RED process a group id matching the device's owning group. Privileged: true is a bench test, not the production design.

On this page
A reachable editor and a working output pin are two different paths, and the deployed create options only paved the first. The module fails at GPIO because the container lacks two things: the device node the GPIO backend opens, and a process identity permitted to open it. Bind the one device the backend actually opens, /dev/gpiomem for the rpi-gpio nodes on a Raspberry Pi, and give the Node-RED process a group id equal to the device's owning group id on the Pi. Keep Privileged: true for the bench test only; the production design is the specific device bind plus the matching group, and nothing wider.
Two paths: the editor loads, the helper cannot reach hardware #
The create options publish host port 80 to container port 1880/tcp, and the editor answers at that address, so path one, browser to runtime to container port, is intact:
{
"HostConfig": {
"PortBindings": { "1880/tcp": [ { "HostPort": "80" } ] },
"Privileged": true
}
}
Path two never leaves the Pi: a flow message reaches the rpi-gpio out node, which spawns the Python helper from /usr/src/node-red/node_modules/@node-red/nodes/core/hardware/nrgpio.py, and the helper must open a device node to reach the header. The block above binds no device, so that path has no route into the hardware at all, and nothing about ports can repair it. Inside the container the editor binds 1880/tcp, a high port any process may open, and the runtime opens the host-side port on the container's behalf; the low-port rule that trips a non-root web server never applies here, which is why the editor works while the pins do not. That distinction is the subject of why a non-root container process cannot bind a low port, a failure that looks similar and has a different cause.
Read the first error, not the last one #
The log tells the story in order, so read it front to back. All three outputs, the buzzer on GPIO20 and the relays on GPIO26 and GPIO16, die at the same line of the helper, the setup call GPIO.setup(pin,GPIO.OUT), with the same reported error. The entries mean:
RuntimeError: No access to /dev/mem. Try running as root!— the helper's mapped GPIO access failed, and the message proposes root because root passes any permission check.- the lines reporting each node closed — the helper behind that node exited after its traceback.
nrpgio python command not running— a later output arrived at a helper that no longer exists; it is the consequence, not a second fault.
Injecting more values into the flow cannot restart a helper that exited during setup. The image itself is sound: it was built for linux/arm/v7 with docker buildx build --platform linux/arm/v7, and the editor runs, so the fault is scoped to device access rather than to the build. Correct the access path, redeploy the module, and only then judge the pins.
Why Privileged: true leaves the same error #
Privilege decides what the runtime lets the container reach; identity decides who the process is, and the privilege flag changes neither the user nor its groups. The module's Node-RED process and the helper it spawns run as the image's own non-root account, and a Pi device node is opened by comparing numbers: root, or a process holding a group id that matches the node's owning group. The long-standing guidance for /dev/mem on a Pi lists the escapes: run as root, make the program setuid or setgid, or add the user to the owning group. The same check runs inside the container against the same numeric owner and group, so Privileged: true supplies the device node but not the identity, and the error stands.
Two things are therefore missing at once in the deployed block: no Binds entry for the device, and no group id matching it. The three sample options that circulate for this exact case, the SenseHat-style bind of /dev/i2c-1, the bind of /dev/gpiomem and the blanket bind of /sys, are discovery tools, and each was paired with Privileged: true to remove every other gate while the right node is found. Keep in mind what that flag trades away: the container-to-host boundary you are deciding how much of it to keep is the same one that decides whether a flow may reboot the host PC from Node-RED running in a container.
Bind the device the backend actually opens #
Which node belongs in the block is decided by the backend, not by preference. The rpi-gpio nodes run the RPi.GPIO Python library, a memory-mapping backend, so the first choice is the Pi's dedicated GPIO memory device:
{
"HostConfig": {
"Binds": [ "/dev/gpiomem:/dev/gpiomem" ]
}
}
- Bind /dev/gpiomem first for direct GPIO outputs: it exposes the GPIO memory and nothing else, the narrowest working choice for a memory-mapping backend.
- Bind /dev/i2c-1 only when the accessory's own library talks over that bus, as SenseHat-style modules do; a bus bind does not substitute for direct GPIO access.
- Bind /sys only when the backend demonstrably walks that tree, and never as a default: it is the share-everything option, and it exposes far more than the flow needs.
The same Binds mechanism carries any host device into a Node-RED container, serial ports included, as walked through in exposing a serial port to Node-RED in a Docker container. A bind makes the node exist inside the container; it grants no permission by itself, and the identity half is the part most deployments miss. If an open still fails with the node present and the group matched, the runtime's device access policy is the last gate: pass the node through the create option that registers a device and sets the runtime's allow rule, rather than only bind-mounting the file.
Worked example: opening /dev/gpiomem as a non-root module process #
The inputs:
- The node on the Pi: /dev/gpiomem, a character device owned by root, numeric id 0, group gpio, mode 0660, shown by
ls -l /dev/gpiomemascrw-rw----. These are the node's standard Raspberry Pi OS permissions, and they match the report behind this kind of failure: a container user with no write access to /dev/gpiomem. - The process: for this example, the module runs Node-RED as uid 1000 with one group, 1000. These are example values, so read the real ones with
idinside the module, and the group's real number on the Pi withgetent group gpio; 999 is the value used here as the example.
The rule, in words: the kernel compares numbers, never names. A read/write open succeeds when the process's effective uid equals the node's owner id, in which case the owner bits decide, or when any of the process's group ids equals the node's group id, in which case the group bits decide. Failing both, only the other bits apply. Mode 0660 decodes as owner read plus write (4 + 2 = 6), group read plus write (4 + 2 = 6), others none.
The arithmetic:
- Owner check: process uid 1000 against owner id 0 — no match, so the owner bits are unused.
- Group check: the process groups {1000} against the owning group's id, 999 on this example Pi — empty overlap, so the group bits are unused.
- Other bits: 0 — nothing granted.
The open is denied, RPi.GPIO reports its one failure message, the helper exits, and every later output hits the not-running error.
The threshold is a single numeric equality: one of the process's group ids must equal the owning group's id. Add 999 as a supplementary group of the container process, through the create option that appends supplementary groups or in the Dockerfile by adding the Node-RED user to a group created with that numeric id, and the groups become {1000, 999}; the group check now matches, the rw- group bits apply, and the open succeeds. Running the whole process as root passes the owner check instead, and that is precisely the shortcut to remove before production. The same numeric-identity mismatch, worked through on another container runtime, is the subject of resolving Podman UID mapping for Ignition bind mount permission errors.
Production checklist for this module #
- Put the connected loads in a safe state before any output test, and check each wire against the configured BCM number, GPIO20 for the buzzer and GPIO26 and GPIO16 for the relays, so a numbering-convention mismatch cannot energize the wrong terminal.
- On the native Pi, the Buster installation where the flow works, record the identity that succeeds: the account, its groups from
id, and the backend in use. - Read the device facts on the Pi:
ls -l /dev/gpiomem /dev/memfor owner, group and mode, andgetent group gpiofor the numeric id. - Read the module's effective identity from inside the running module with
id, never from the Dockerfile's intent. - Write the create options with the single device bind the backend opens and the supplementary group whose numeric id matches the owning group, and drop
Privileged: truefrom the block. - Redeploy, confirm no traceback when the flows start, then command each pin and watch the load.
- If an open is still denied with the node present and the group matched, pass the node as a registered device so the runtime's device policy allows it, and retest.
Questions asked
Why does the error mention /dev/mem when the recommended bind is /dev/gpiomem?
The text comes from the RPi.GPIO Python library that the rpi-gpio nodes run, and it is the library's one failure message for mapped GPIO access that was denied; it suggests root because root always passes the permission check. Treat root as the diagnostic shortcut it is: bind the GPIO memory device and give the process the matching group id, and the same setup call succeeds without root.
Does adding the device bind change the working editor port mapping?
No. PortBindings and Binds sit in the same HostConfig block but control different things: one publishes network ports, the other passes host paths into the container. Leave the mapping of host port 80 to container port 1880/tcp untouched while you add the device bind and the group id, then retest both after the redeploy, because a JSON typo in the block can take the working mapping down along with it.
Can the module keep Privileged true in production?
It will run, but privilege removes most of the container's isolation: every host device and kernel interface becomes reachable from the module, so one mistaken flow can touch the Pi itself. The production shape is narrower: bind the one GPIO device the backend opens, give the process the owning group's numeric id, and drop the privilege flag once the pins switch correctly under test.
Do I need to rebuild the image to add the group?
Not necessarily. Adding a supplementary group through the container create options takes effect when the module is redeployed, so you can prove the fix without a rebuild. Baking it into the Dockerfile instead, by creating a group with the Pi's numeric gpio group id and adding the Node-RED user to it, suits an image you build once and reuse, because the numeric id must match the group on each host that runs the image.

