Give container access to USB devices via the createOptions

tcochunk 0 Reputation points
2023-05-18T01:32:18.5266667+00:00

I am new to IOT development so please forgive my ignorance. I am trying to create a container and deploy it to raspberry pi thru Azure. I want the container to have access to a certain usb device (access to all usb devices would be acceptable at this point as well). I have updated the createOptions to be the following:


{
    "HostConfig": {
        "Devices": [
            {
                "CgroupPermissions": "rwm",
                "PathInContainer": "/dev/serial/by-id/usb-MicroPython_Board_in_FS_mode_e66118604b659326-if00",
                "PathOnHost": "/dev/serial/by-id/usb-MicroPython_Board_in_FS_mode_e66118604b659326-if00"
            }
        ],
        "Privileged": true
    }
}

the Privileged was trying to brute force all devices. I am trying to connect a Pico board via usb cable to the Pi.

However, when the module starts up i get the following error:

Unhandled exception. System.AggregateException: One or more errors occurred. (Access to the port '/dev/ttyACM0' is denied.)
---> System.UnauthorizedAccessException: Access to the port '/dev/ttyACM0' is denied.
---> System.IO.IOException: Permission denied

When i run the same code on the Pi directly (not in a container) it works as expected.

Any help would be much appreciated

Azure IoT Edge
Azure IoT Edge
An Azure service that is used to deploy cloud workloads to run on internet of things (IoT) edge devices via standard containers.
531 questions
{count} votes

1 answer

Sort by: Most helpful
  1. AshokPeddakotla-MSFT 27,126 Reputation points
    2023-05-18T06:03:24.5733333+00:00

    @tcochunk Welcome to Microsoft Q&A forum!

    Are you following any documentation for the steps?

    Unhandled exception. System.AggregateException: One or more errors occurred. (Access to the port '/dev/ttyACM0' is denied.)
    ---> System.UnauthorizedAccessException: Access to the port '/dev/ttyACM0' is denied.
    ---> System.IO.IOException: Permission denied

    As per the error message, it is related to permissions for accessing the serial port /dev/ttyACM0. This error can occur if the user running the container does not have the necessary permissions to access the serial port.

    To fix this issue, you can try adding the container user to the dialout group on the host, which should grant it access to serial devices. You can do this by adding the following line to your Dockerfile:

    $ sudo usermod -a -G dialout <your-username>
    

    Replace <your-username> with the name of the user that the container runs as.

    After running the command, please log out and log back in for the group changes to take effect. Make sure to restart your Pi as well.

    Once you've added your user to the dialout group and restarted, both running the code directly on the Pi and inside the container should have the necessary permissions to access /dev/ttyACM0.

    Please try above suggestions and let us know if that helps.

    If this answers your query, do click Accept Answer and Yes if this answer helpful. And, if you have any further query do let us know.