Devicemonitor in docker


I’m looking to identify whether a USB device has been removed from my system, so I can adjust my pipeline accordingly. The tool GstDeviceMonitor appears to be suitable, but I’m unable to get it to function within a Docker container.

I attempted to mount the udev folder as suggested in this link here, however, it doesn’t seem to work.

Here’s a snippet of the code I’m using for testing. It successfully detects USB events when run in a native environment, but in a container, it only prints “Device added: xxx” upon startup. The removal or insertion of a device is not detected.

import gi

gi.require_version("Gst", "1.0")
from gi.repository import GLib, Gst


def on_device_added(device_monitor, message):
    device = message.parse_device_added()
    print(f"Device added: {device.get_display_name()}")

def on_device_removed(device_monitor, message):
    device = message.parse_device_removed()
    print(f"Device removed: {device.get_display_name()}")

device_monitor = Gst.DeviceMonitor()
bus_device = device_monitor.get_bus()
bus_device.connect("message::device-added", on_device_added)
bus_device.connect("message::device-removed", on_device_removed)

loop = GLib.MainLoop()
except KeyboardInterrupt:

Could you please let me know what needs to be shared with the Docker system? Thank you!