Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4436

General discussion • SPI from Docker image

$
0
0
Hi all!

I can use my RFID reader via Python fine:

Code:

import RPi.GPIO as GPIOfrom mfrc522 import SimpleMFRC522reader = 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:

Code:

Traceback (most recent call last):  File "/usr/src/app/controller.py", line 30, in <module>    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:

Code:

FROM python:3.9-alpineWORKDIR /usr/src/appCOPY controller .RUN apk add --update --no-cache gcc libc-dev gcompatRUN pip install --index-url=https://www.piwheels.org/simple --no-cache-dir -r requirements.txtCMD ["python", "controller.py"]

Code:

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:

Code:

/usr/src/app #  ls -all /dev/*spi*crw-rw----    1 nobody   nobody    153,   0 Feb  2 19:24 /dev/spidev0.0crw-rw----    1 nobody   nobody    153,   1 Feb  2 19:24 /dev/spidev0.1
and

Code:

/usr/src/app #  whoamiroot
I've tried to change permissions but failed:

Code:

/usr/src/app # chmod 660 /dev/spidev0.0chmod: /dev/spidev0.0: Operation not permitted
I've also tried chown but get the same.

Any ideas? Thanks :)

Statistics: Posted by pperi — Sun Feb 04, 2024 5:54 pm — Replies 0 — Views 38



Viewing all articles
Browse latest Browse all 4436

Trending Articles