I used the official docker image of flask. And installed the rpi.gpio library in the container
pip install rpi.gpio
It's succeeded:
root@e31ba5814e51:/app# pip install rpi.gpio
Collecting rpi.gpio
Downloading RPi.GPIO-0.7.0.tar.gz (30 kB)
Building wheels for collected packages: rpi.gpio
Building wheel for rpi.gpio (setup.py) ... done
Created wheel for rpi.gpio: filename=RPi.GPIO-0.7.0-cp39-cp39-linux_armv7l.whl size=68495 sha256=0c2c43867c304f2ca21da6cc923b13e4ba22a60a77f7309be72d449c51c669db
Stored in directory: /root/.cache/pip/wheels/09/be/52/39b324bfaf72ab9a47e81519994b2be5ddae1e99ddacd7a18e
Successfully built rpi.gpio
Installing collected packages: rpi.gpio
Successfully installed rpi.gpio-0.7.0
But it prompted the following error:
Traceback (most recent call last):
File "/app/hello/app2.py", line 2, in <module>
import RPi.GPIO as GPIO
File "/usr/local/lib/python3.9/site-packages/RPi/GPIO/__init__.py", line 23, in <module>
from RPi._GPIO import *
RuntimeError: This module can only be run on a Raspberry Pi!
I tried the method in this link, but it didn't work: Docker Access to Raspberry Pi GPIO Pins
I want to know if this can be done, and if so, how to proceed.