I am a complete beginner at Docker, so please do easy on me.
I am trying to deploy a Django project in a Docker container on a Raspberry Pi 3B, but I am running into a problem accessing the GPIO ports.
Every time I try to initialise Docker with “sudo docker-compose up” I get the error: “RuntimeError: No access to /dev/mem. Try running as root!”
From what I have read, in order to get the Docker container to communicate with the GPIO ports the ‘user’ has to be a part of the ‘gpio’ group.
My questions are:
- How can make the user a member of the GPIO group from either the Docker file or the docker-compose.yml?
- Is there a better way of gaining access to the GPIO ports from Docker?
Docker File:
FROM python:3.8-alpine
ENV PATH="/scripts:${PATH}"
COPY ./requirements.txt /requirements.txt
RUN apk add --update --no-cache --virtual .tmp gcc libc-dev linux-headers
RUN pip install -r /requirements.txt
RUN pip install RPi.GPIO
RUN pip install apscheduler
RUN apk del .tmp
RUN mkdir /poolproject
COPY ./poolproject /poolproject
WORKDIR /poolproject
COPY ./scripts /scripts
RUN chmod +x /scripts/*
RUN mkdir -p /vol/web/media
RUN mkdir -p /vol/web/static
RUN adduser -D user
RUN chown -R user:user /vol
RUN chmod -R 755 /vol/web
USER user
CMD ["entrypoint.sh"]
docker-compose.yml
version: '3.7'
services:
app:
privileged: true
build:
context: .
ports:
- "8000:8000"
volumes:
- ./poolproject:/poolproject
command: sh -c "python manage.py runserver 0.0.0.0:8000"
environment:
- DEBUG=1