Docker, Access to Raspberry Pi4 GPIO Pins

When running MozilaIOT in Docker on the Raspberry Pi 4, how can we expose the GPIO pins to the GPIO addon?

Running the following doesn’t seem to work:

docker run -v /sys/class/gpio:/sys/class/gpio

This is the error I get:

Failed to start add-on GPIO: No permissions to /sys/class/gpio/export

Here are some instructions: https://stackoverflow.com/a/48234752

You’ll also need the proper permissions inside the container, which I’ve just merged a fix for. The images are rebuilding now.

I’ve followed those instructions with

-v /sys/class/gpio:/sys/class/gpio

unfortunately it still doesn’t work, even running

–privileged

. Here;s my set up:

> docker run \
    --device /dev/gpiomem:/dev/gpiomem \
    -d \
    -e TZ="Europe/London" \
    -e Country="United Kingdom" \
    -e Language="English" \
    -v /path/to/shared/data:/home/node/.mozilla-iot \
    -v /sys/class/gpio:/sys/class/gpio \
    --network="host" \
    --log-opt max-size=1m \
    --log-opt max-file=10 \
    --name webthings-gateway \
    --restart=unless-stopped \
    mozillaiot/gateway:arm

Are you using the latest Docker image? I rebuilt it a couple days ago with a fix for GPIO.

No I wasn’t, I’ve just replaced the image. No error now, thank you for that. I still can’t seem to add GPIO pins, should they appear as things?

You need to first configure the adapter via Settings -> Add-ons, then click Configure for GPIO. After setting up and applying your configuration, they’ll appear as things.

I’ve configured and not had any error but there’s no sign of it as a thing.

Did you click the + button on the Things screen and add it, or are you not even seeing it there?

No unfortunately not

Can you take a screenshot of the add-on configuration?

I’d been trying a few different pin numbers.

There seems to be no tag called arm.
Are you sure that’s the command you used?

I tried it on my pi 4, and the GPIO adapter fails due to /sys being read-only.
The privileged mode fixes it, though.

docker run \
    --privileged \
    -d \
    -e TZ="Europe/London" \
    -e Country="United Kingdom" \
    -e Language="English" \
    -v /path/to/shared/data:/home/node/.mozilla-iot \
    -v /sys/class/gpio:/sys/class/gpio \
    --network="host" \
    --log-opt max-size=1m \
    --log-opt max-file=10 \
    --name webthings-gateway \
    --restart=unless-stopped \
    mozillaiot/gateway

That’s what I was using at the time but your right, I’ve since changed that to:

mozillaiot/gateway: latest

I wasn’t sure about using

–privileged

As the https://stackoverflow.com/a/48234752 thread seemed to advise against it

Does yours work without privileged?

Has anyone got this working without privileged? Thanks

I wouldn’t advise it either but that’s the only way it worked for me.

Hi t1m1, I new here. I have the same problem with the GPIO but also with the I2C add-on. I’m using a Pi4 with Ubuntu 20 where I succesfully installed the gateway. The errors are gpio-adapter: Failed to … /sys/class/gpio/export and generic-sensors-adapter: Failed to start … No permissions for I2C resource. After installing docker (it wasn’t) I tried your solution:
docker run \

–privileged
-d
-e TZ=“Europe/Madrid”
-e Country=“Spain”
-e Language=“English”
-v /path/to/shared/data:/home/.webthings
-v /sys/class/gpio:/sys/class/gpio
–network=“host”
log-opt max-size=1m
–log-opt max-file=10
–name webthings-gateway
–restart=unless-stopped
MYPATH/gateway
but getting the error: docker: invalid publish opts format (should be name=value but got ‘rivileged’). Problably is a very simple question but I’m getting started with the gateway.
Thanks!