SPI via Docker — Permission denied

The Raspberry Pi is a series of credit card-sized single-board computers developed in the United Kingdom by the Raspberry Pi Foundation to promote the teaching of basic computer science in schools and developing countries.

Post Reply
User avatar
/RaspberryPi
Corporate
Posts: 2449
Joined: Wed Jun 05, 2019 1:29 am

SPI via Docker — Permission denied

Post by /RaspberryPi »


Hi,

I can use my RFID reader via Python fine: ``` import RPi.GPIO as GPIO from mfrc522 import SimpleMFRC522

reader = SimpleMFRC522()

try: id = reader.read()[0] print("The ID for this card is:", id) finally: GPIO.cleanup() ```

However, I'm getting the following error when running from a Docker container: Traceback (most recent call last): File "/usr/src/app/controller.py", line 30, in reader = SimpleMFRC522() File "/usr/local/lib/python3.9/site-packages/mfrc522/SimpleMFRC522.py", line 14, in __init__ self.READER = MFRC522() File "/usr/local/lib/python3.9/site-packages/mfrc522/MFRC522.py", line 130, in __init__ self.spi.open(bus, device) PermissionError: [Errno 13] Permission denied

My Docker setup is the following: ``` FROM python:3.9-alpine

WORKDIR /usr/src/app

COPY controller .

RUN apk add --update --no-cache gcc libc-dev gcompat RUN pip install --index-url=https://www.piwheels.org/simple --no-cache-dir -r requirements.txt

CMD ["python", "controller.py"] ```

``` version: '3.8'

services: controller: build: . privileged: true volumes: - /lib/modules:/lib/modules - /sys:/sys - /dev:/dev devices: - /dev/spidev0.0 - /dev/spidev0.1 ```

There's some discussion online about giving users access to SPI (and other GPIO stuff), but they focus on non-root access, and I don't think they apply here as I can actually use SPI fine from host and I'm using the default root user inside Docker. It seems to be a permissions issue as if I open a terminal inside my running container I can see the following: /usr/src/app # ls -all /dev/*spi* crw-rw---- 1 nobody nobody 153, 0 Feb 2 19:24 /dev/spidev0.0 crw-rw---- 1 nobody nobody 153, 1 Feb 2 19:24 /dev/spidev0.1

and

/usr/src/app # whoami root

I've tried to change permissions but failed:

/usr/src/app # chmod 660 /dev/spidev0.0 chmod: /dev/spidev0.0: Operation not permitted

I've also tried chown but get the same.

Any ideas? Thanks :)
submitted by /u/ppperi
[link] [comments]

Source: https://www.reddit.com/r/raspberry_pi/c ... on_denied/
/RaspberryPi
Post Reply

Return to “Raspberry Pi Forum”