• Error when trying to run depthai-python API in a Docker container

I am able to successfully run depthai-python API examples natively on macOS and I have been developing this way for a while. However, now I need to run in a Docker container.

I'm trying to follow the instructions from here.

I have the following software:

  • macOS Monterey 12.6.8
  • Docker Desktop for macOS Version 3.6.0 (3.6.0.5487)
  • XQuartz 2.7.11 (xorg-server 1.18.4)

I am able to successfully pull the docker image:

docker pull luxonis/depthai-library

But when I run:

docker run --rm \
    --privileged \
    -v /dev/bus/usb:/dev/bus/usb \
    --device-cgroup-rule='c 189:* rmw' \
    -e DISPLAY=$DISPLAY \
    -v /tmp/.X11-unix:/tmp/.X11-unix \
    luxonis/depthai-library:latest \
    python3 /depthai-python/examples/ColorCamera/rgb_preview.py

I get this error:

[2023-09-05 20:14:48.879] [depthai] [warning] USB protocol not available - If running in a container, make sure that the following is set: "-v /dev/bus/usb:/dev/bus/usb --device-cgroup-rule='c 189:* rmw'"
Traceback (most recent call last):
  File "/depthai-python/examples/ColorCamera/rgb_preview.py", line 24, in <module>
    with dai.Device(pipeline) as device:
RuntimeError: No available devices

Thoughts?

    Hi Craftonix
    Few things you could try/check:

    1. Docker Privileges: Ensure that the --privileged flag is indeed granting the container the necessary privileges to access the host's USB devices.

    2. USB Device Mapping: You have mapped /dev/bus/usb from your host to the Docker container using the -v /dev/bus/usb:/dev/bus/usb flag which seems correct. Ensure that the devices are indeed available under /dev/bus/usb in your macOS system.

    3. Display Environment Variable: You are mapping the $DISPLAY environment variable and the
      /tmp/.X11-unix directory to enable GUI display from the container. Ensure that the XQuartz is running and is configured to allow connections from network clients (you can find this option in XQuartz preferences under the “Security” tab).

      Additional Commands:
      Before running the Docker command, run xhost + in your terminal to allow connections to the X server.
      Try adding --network host to your Docker command, which sometimes solves connectivity issues.

    4. Docker Daemon Restart: Sometimes, restarting the Docker daemon can resolve issues with device access.

    Hope this helps,
    Jaka

    Hi Jaka,

    This is for the OAK-D PoE and OAK-D S2 PoE. These are both network devices, not USB. But still I want to try your suggestions because I am familiar with Docker and priviledges.

    What do you mean by (1) ? How do I ensure?

    This is what I get inside the container:

    docker run --rm -it    --privileged --net=host    -v /dev/bus/usb:/dev/bus/usb     --device-cgroup-rule='c 189:* rmw'     -e DISPLAY=$DISPLAY     -v /tmp/.X11-unix:/tmp/.X11-unix     luxonis/depthai-library:latest bash
    root@docker-desktop:/# ls /dev/bus
    usb
    root@docker-desktop:/# ls /dev/bus/usb
    root@docker-desktop:/#

    Regarding (2): macOS does not have /dev/busSo, I don't understand what you are mapping with -v option.

    I have verified (3) and (4) using this. I can run X11 apps (e.g. xeyes, gnome-calculator, xclock) and display them in XQuartz.

    Also, since the Luxonis image does not have ifconfig, I used the bash image to verify that --net=host is actually granting access to all the network interfaces of the host.

    To diagnose this further, I think we should ignore the GUI/display part (since I know this is working with other images) and focus on the networking and USB parts. So, I tried bootloader_version.pywhich is a terminal-only CLI:

    docker run --rm     --privileged --net=host    -v /dev/bus/usb:/dev/bus/usb     --device-cgroup-rule='c 189:* rmw'     -e DISPLAY=$DISPLAY     -v /tmp/.X11-unix:/tmp/.X11-unix     luxonis/depthai-library:latest     python3 /depthai-python/examples/bootloader/bootloader_version.py
    [2023-09-06 12:42:48.498] [depthai] [warning] USB protocol not available - If running in a container, make sure that the following is set: "-v /dev/bus/usb:/dev/bus/usb --device-cgroup-rule='c 189:* rmw'"
    No devices found

    Still the same error.

    Are you sure you have tried running the Luxonis docker image on Docker Desktop for macOS ?

    • erik replied to this.

      Hi Craftonix ,
      Does it work outside docker, on the macos directly?

      Yes, as I already mention in the first sentence of this post: "I am able to successfully run depthai-python API examples natively on macOS and I have been developing this way for a while."

        Hi Craftonix
        Could you try pinging the device to see if it can correctly access it. I would assume you are running them through a router?

        Thanks,
        Jaka

        Yes, I can ping the device from inside my container. Both the device and my laptop (which is running Docker Desktop for macOS) are connected to the same router which gives them a DHCP address. Somthing like:

        Device: 192.168.1.22
        Laptop: 192.168.1.36

          Hi Craftonix
          That's very strange. Have you tried directly specifying the IP address using DeviceInfo?
          What bootloader version are you using?

          Thanks,
          Jaka

          a month later

          I'm also have a similar issue.
          I'm running docker desktop on Mac m2

          OAK 1 D POE

          This is the error:
          [2023-10-05 18:48:42.156] [depthai] [warning] USB protocol not available - If running in a container, make sure that the following is set: "-v /dev/bus/usb:/dev/bus/usb --device-cgroup-rule='c 189:* rmw'"

          this is from my docker-compose:
          devices:

          • /dev/bus/usb:/dev/bus/usb

          command: ["--device-cgroup-rule=c 189:* rmw"]

          if I test the camera directly on the host it runs. But in docker I can't access.

            Hi keggy
            AFAIK there is currently no USB pass-through option for MacOS, since it doesn't expose the ports as linux does: /dev/bus/usb:/dev/bus/usb.
            You will need to make a VM/use parallels to achieve that on a mac.

            Thanks,
            Jaka

              jakaskerl thanks for the reply. Even if I use the OAK with POE?
              I use an USB-C<-> Lan Adapter.

              I als try do run it on my VM but my Mac is with Apple Silicon.
              I let u know

              I tried on Ubuntu VM in Parallels and it worked!

              and as suggested I use in my Docker-Compose
              "…

              devices:

                - /dev/bus/usb:/dev/bus/usb

              …"

                keggy I don't understand: are you running Docker inside the Ubuntu VM ?

                  Craftonix

                  At first I tried directly with docker desktop on may Mac.

                  Then i installed docker (but not desktop) on my Ubuntu VM which is running in parallels