I'm trying to run a simple docker container with a python base image to control the LEDs on my RPi4.

The Dockerfile compiles fine and I'm running it as follows: docker run --rm -ti --privileged --device /dev/gpiomem:/dev/gpiomem -d led_blinker bash

Once inside the docker container I run a ls -l /dev/gpiomem and I get

root@ca1506d00cc5:/# ls -l /dev/gpiomem
crw-rw---- 1 nobody nogroup 246, 0 Dec 30 21:47 /dev/gpiomem

I try to do

root@ca1506d00cc5:/# chown root.root /dev/gpiomem
chown: changing ownership of 'dev/gpiomem': Operation not permitted

But when I run a whoami I get I'm the root user. What is that I'm missing?

PS. I have also added the flag --user root and got the same results.

  • Did you test that it really doesn't work the way it is?
    – PMF
    Jan 4 at 15:17
  • I did. I'm trying to use gpiozero library and it throws an error when trying to access the device that I need root access. Looking at this post seems I need to set the correct permisions, which I can't do for some reason Jan 4 at 15:56
  • That post is for running without docker (and it is outdated as well, as this has been fixed meanwhile). I have never used docker on the Pi, but (here)[github.com/dotnet/iot/tree/main/samples/led-blink] is another example that shows that it should normally be working just fine.
    – PMF
    Jan 4 at 16:23
  • I ended up doing a fresh install on the pi, and the post you linked worked, and was able to get mine to work as well. I think experimenting with Docker on the pi might have messed up some config Jan 5 at 20:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.