I would like to access the GPIO from within a docker container, but keep getting permission errors.
I installed the jetson nano as described in https://developer.nvidia.com/embedded/learn/get-started-jetson-nano-devkit.
For accessing the GPIO, I used the description here: https://github.com/NVIDIA/jetson-gpio
From within python in the bare system, I then can use the GPIO.
However, when accessing it from within a docker container, the respective user needs to be in the gpio group to access /sys/class/gpio/export and unexport. With a container user having sudo rights, I see that when calling python with sudo and then importing Jetson.GPIO, I can use it and have permission. To grant that permission to the container user, I add a user in the respective group in the Dockerfile:
Create a non-root user with the same uid as on the host to allow proper file
permissions created from the container in volumes. Since it is not root, allow
calling sudo without password when required.
RUN groupadd -f -r -g $gid_gpio gpio
RUN groupadd -f -r -g 1000 user
gpio needs to be main group, otherwise we get permission problems
RUN useradd -M --uid $uid -g $gid_gpio user --groups uucp,$gid,user
&& echo ‘user ALL=(ALL) NOPASSWD:ALL’ >> /etc/sudoers.d/user
&& echo ‘Defaults exempt_group+=user’ >> /etc/sudoers.d/user
&& chmod a=r,o= /etc/sudoers.d/user
With this, in the container’s shell, I can stat the /sys/class/gpio/export and /unexport. However, from python, I still can’t import Jetson.GPIO without permission errors: os.access() says I didn’t have access to the paths (as used in https://github.com/NVIDIA/jetson-gpio/blob/master/lib/python/Jetson/GPIO/gpio.py#L31 [the issue remains when calling os.access with effective_ids=True])
For the sake of testing, I uncommented the lines checking access, but then ran into trouble in https://github.com/NVIDIA/jetson-gpio/blob/master/lib/python/Jetson/GPIO/gpio_pin_data.py#L241. Here, paths ‘/proc/device-tree/compatible’ and ‘/proc/device-tree/chosen/plugin-manager/ids’ are needed. If I try to import them as volumes
I am not successful. However, I an import them with a different name, e.g.:
But then, finally, I cannot get past https://github.com/NVIDIA/jetson-gpio/blob/master/lib/python/Jetson/GPIO/gpio_pin_data.py#L249.
Interestingly, I haven’t found any examples of how to use the GPIO from a docker container - If anyone can give me hints on how to properly do it, I’d greatly appreciate it.