Score:0

Docker App Not Always Finding Serial Ports In Ubuntu 20.04

jp flag

I am busy with an IoT type application that requires physical hardware that is connected through a serial port. We have opted to use the Azure IoT Edge architecture to deploy the application on the PC that exists on premise. This helps our DevOps cycle.

To use Azure IoT Edge requires that our application is containerized and thus exposing serial ports can be quite a challenge. The PC is 64-bit and is running Ubuntu 20.04 and does have multiple USB, serial and LAN ports that we can plug devices into.

We have followed this great tutorial from Losant to set this up.

Our container creation options look like this:

{
  "HostConfig": {
    "PortBindings": {
      "80/tcp": [
        {
          "HostPort": "5000"
        }
      ]
    },
    "Privileged": true,
    "Volumes": {
      "/dev": {}
    }
  }
}

We map the application our application's port 80 to port 5000 on the PC and we set the Volumes and Privileged tag as suggested in the tutorial link above.

The device itself is connected through USB and thus we have had to install a driver on Ubuntu 20.04 from the FTDI website.

My question:

In some cases our application will find the serial port (tty/USB0), but in most cases it will not. If we power cycle the PC with the device connected the application usually finds the device. How can we change the PC setup / docker setup / application setup so that it always finds the device?

NOTE: This is a duplication of this question on StackOverflow as I was not sure whether the question belonged there or here.

in flag
When the Docker container does not find the connected device, what is the Terminal output of `sudo lsusb`? I’m wondering if the device is being picked up at a different location on the USB bus or not at all.
itstudes avatar
jp flag
After running that command I get: `Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub` `Bus 001 Device 003: ID 0403:6015 Future Technology Devices International, Ltd Bridge(I2C/SPI/UART/FIFO)` `Bus 001 Device 002: ID 15a2:0300 Freescale Semiconductor, Inc. ADP102 SERIAL DIO` `Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub` Device 003 looks like the FTDI device, so it seems to show up at the PC level.
in flag
When you run `docker info`, do you see `Udev Sync Supported: true`? If this is false, then the USB Device will always need to be given the very same device ID, which is not always possible as they're handed out based on varying factors, such as warm up time ...
itstudes avatar
jp flag
So the [tutorial from Losant](https://www.losant.com/blog/how-to-access-serial-devices-in-docker) above talks about those udev rules. So I think you are right about that. I ran that `docker info` command and I couldn't see anything to do with Udev settings. I think my format for the "Volumes" is not quite correct in the code section above. I was looking at [this docker link on Volumes](https://docs.docker.com/storage/volumes/#start-a-container-with-a-volume) and I think you're supposed to use "Mounts". Once I get that format right I'm hoping things will work correctly.
Score:0
jp flag

This was actually just an unfortunate misuse of the syntax for volumes. This docker link was helpful.

The resolved syntax is as follows:

{
    "HostConfig": {
        "Binds": [
            "/dev:/dev"
        ],
        "PortBindings": {
            "80/tcp": [
                {
                    "HostPort": "5000"
                }
            ]
        },
        "Privileged": true
    }
}

After resolving that everything worked as expected.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.