I am setting up a Raspberry Pi 3b+ running Raspbian Stretch with IoT edge. This requires Docker images and containers for the modules. I am trying to get a module to take sensor data from the GPIO pins and send that to another module. When I attempt to use the directory where the GPIO information should be /sys/class/gpio/export
I get that it does not exist. It seems like this is because docker doesn't have privileged
set to true
, however because I am doing this through IoT edge I can't input this through the CLI.
According to this article https://thenewstack.io/tutorial-connect-and-configure-raspberry-pi-as-an-azure-iot-edge-device/ I need to put
{
"HostConfig": {
"Privileged": true
}
}
under create options, which I have done by putting this in the deployment manifest and publishing. I still get this error:
/bin/chgrp: cannot access '/sys/class/gpio/export': No such file or directory
. I've tried elevating my privileges by granting my docker container USER sudo
but I believe this is occurring because the docker container isn't truly being run with privileged settings. This is the post that makes me believe this: Docker Access to Raspberry Pi GPIO Pins , it implies that it is as simple as running docker with privileged.
I have tried putting the create options to privileged. Here is a snapshot from my IoT Edge Module Details page on the Azure Portal: https://i.stack.imgur.com/QuHc3.png
I've also put
{
"HostConfig": {
"Privileged": true
}
}
inside of the CreateOptions
field within deployment.template.json
Here is my dockerfile:
FROM arm32v7/node:8-slim
WORKDIR /app/
COPY package*.json ./
RUN apt-get update
RUN apt-get -y install sudo
RUN useradd -m docker && echo "docker:docker" | chpasswd && adduser docker sudo
RUN apt-get install -y python
RUN apt-get install -y build-essential
RUN npm install --production
COPY app.js ./
RUN sudo groupadd gpio
RUN sudo usermod -aG gpio docker
RUN su docker
RUN sudo chgrp gpio /sys/class/gpio/export
RUN sudo chgrp gpio /sys/class/gpio/unexport
RUN sudo chmod 775 /sys/class/gpio/export
RUN sudo chmod 775 /sys/class/gpio/unexport
USER docker
CMD ["node", "app.js"]
Note: this is all in Visual Studio Code. Once this is all in order, I right click my deployment.template.json
and click Build IoT Solution
. Then I right click my Edge device under the Azure IoT Hub Devices
dropdown and select Create Deployment for Single Device
then I select the deployment.arm32v7.json
under ./moduleName/config
.
I expect for the /sys/class/gpio/export
directory to actually exist within the container as it does exist within the RPi.
What actually happens here is that I get this error:
/bin/chgrp: cannot access '/sys/class/gpio/export': No such file or directory
The command '/bin/sh -c sudo chgrp gpio /sys/class/gpio/export' returned a non-zero code: 1
Any insights or help is greatly appreciated, thank you.