Problem running a Docker container for RFID-RC522 on an Raspberry Pi 4

168 Views Asked by At

I got an error when I try to run a running a Docker container for RFID-RC522 on a Raspberry Pi 4. Test program is written in Phyton, and I can't figure out what the problem is

**This is my configuration and testfiles: **

Raspberry Pi OS (64-bit). Docker version 20.10.23, build 7155243 RFID-RC522 from Arduino.

Python test program:

#!/usr/bin/env python

import RPi.GPIO as GPIO
from mfrc522 import SimpleMFRC522
reader = SimpleMFRC522()
try:
        id, text = reader.read()
        print(id)
        print(text)
finally:
        GPIO.cleanup()

Dockerfile:

#FROM python:3.8-alpine
FROM python:3.8-slim
RUN apt-get update && apt-get install build-essential -y
RUN pip install smbus2
RUN pip install spidev
RUN pip install --no-cache-dir rpi.gpio
RUN pip install mfrc522
RUN mkdir /app
ADD . /app
WORKDIR /app
RUN pip install -r requirements.txt
CMD ["python", "Read.py"]

Build Container: sudo docker build -t read-rfid-python-app .

Run Container: docker run -it read-rfid-python-app

And the error:

Traceback (most recent call last):
  File "Read.py", line 6, in <module>
    reader = SimpleMFRC522()
  File "/usr/local/lib/python3.8/site-packages/mfrc522/SimpleMFRC522.py", line 14, in __init__
    self.READER = MFRC522()
  File "/usr/local/lib/python3.8/site-packages/mfrc522/MFRC522.py", line 130, in __init__
    self.spi.open(bus, device)
FileNotFoundError: [Errno 2] No such file or directory

Have I missed installing something in the Dockerfile? Everything works as intended outside of Docker.

The problem is very similar to 'https://stackoverflow.com/questions/68873696/unable-to-connect-rc522-rfid-module-to-raspberry-pi-4'. With that difference is that it is only when it is placed in a container that the problem occurs. Does something need to be done about SPI?

Thanks in advance!

Br

Mark Stone

0

There are 0 best solutions below