Sandy
Sandy

Reputation: 79

Not able to deploy Python program from Azure IOT Edge to Rasberry Pi

I installed the IOT Edge runtime using below link:
https://learn.microsoft.com/en-us/azure/iot-edge/how-to-install-iot-edge-linux-arm

I am following the below tutorial to deploy a docker image to IOT Edge (Rasberry Pi):
https://learn.microsoft.com/en-us/azure/iot-edge/quickstart-linux
and able to deploy the tempSensor image to my Rasberry Pi

I decided to deploy my own program "blink.py".
I created the program and its working fine in the local Rasberry Pi using below command:

$docker container run --device /dev/gpiomem -d blink

I followed the below steps to deploy my own program from Azure IOT Edge portal:
1.) Create a docker image using Dockerfile:

FROM arm32v7/python:2.7.15-stretch
COPY blink.py
CMD ["python","./blink.py"]

then ran the command:

$docker build -t "blink" ./

2.) Now i pushed the image to Azure container Registry. Followed below steps:

a.) Login to Azure container registry

$docker login blink.azurecr.io

b.) Push to Azure container registry

$docker tag blink link.azurecr.io/blink
$docker push blink.azurecr.io/blink

3.) Deploy image in Azure container registry to IOT Edge device using below link: https://learn.microsoft.com/en-us/azure/iot-edge/quickstart-linux#deploy-a-module

I see a container image created in the Raspberry Pi as "blink.azurecr.io/blink"
I see that IOTEdge runtime tried to deploy this image as container but it failed.
When i try to see the logs using command

>docker logs blink


It shows an error:

Traceback (most recent call last):
  File "./blink.py", line 6, in <module>
    GPIO.setup(4,GPIO.OUT) 
RuntimeError: No access to /dev/mem. Try running as root!



Seems like some access issue but not sure how to solve it? Do i need to put anything in the createOptions while deploying the edge module from azure portal ?

-Sandy

Upvotes: 0

Views: 488

Answers (2)

Sandy
Sandy

Reputation: 79

ok so it worked! I provided below in the createOptions:

{
    "HostConfig": {
        "Devices": [
            {
                "PathOnHost": "/dev/gpiomem",
                "PathInContainer": "/dev/gpiomem",
                "CgroupPermissions": "rwm"
            }
        ]
    }
}

After re-deploying.. it worked, Hurray !!!!

Upvotes: 0

Michael Xu
Michael Xu

Reputation: 4432

From the error log, it seems that the module has no permission to access device/gpio. sudo should be able to used inside the container. You can try to add the following command in Dockerfile.

RUN apt-get update && apt-get -y install sudo

RUN useradd -m docker && echo "docker:docker" | chpasswd && adduser docker sudo

This topic in stackoverflow as a reference.

Upvotes: 0

Related Questions