Search code examples
node.jsdockerdebianraspbianudev

How to set correct group member for dockerized nodeJS application


I need to run a docker container with an application using rpio package.

I do not understand this part:

By default the module will use /dev/gpiomem when using simple GPIO access. To access this device, your user will need to be a member of the gpio group, and you may need to configure udev with the following rule (as root):

$ cat >/etc/udev/rules.d/20-gpiomem.rules <<EOF
SUBSYSTEM=="bcm2835-gpiomem", KERNEL=="gpiomem", GROUP="gpio",
MODE="0660" EOF

For access to i²c, PWM, and SPI, or if you are running an older kernel which does not have the bcm2835-gpiomem module, you will need to run your programs as root for access to /dev/mem.

As I'm running my nodeJS application in a docker image/container, I don't understand how to set group member and which member name and where to call that udev rules command.

I'm very thankful for every explanation.


Solution

  • The docker user (should be the logged in user, e.g. "pi") needs to be in the "gpio" group.

    # see all groups the user is assigned to
    groups
    
    # if the user is not assigned to gpio, run the following:
    sudo adduser $(whoami) gpio
    

    You need to make the device /dev/gpiomem available inside the docker container.

    # e.g.
    docker run -d --device /dev/gpiomem <image>