Accessing a usb camera from a docker container in Linux?

Hi all,

I’m using Docker Desktop for Ubuntu (v4.9.0).

I’m building a docker image with the purpose of sharing a working installation of a custom stereo camera driver. (based on an Ubuntu Focal image with the needed dependencies on top of it)
All good so far, I have a working image except for not being able to access the camera device (/dev/video0) from the container.
Based on my search on how this should be done, I found the following options:

  1. Specifying the device: docker run -it --device /dev/video0 ...

docker: Error response from daemon: error gathering device information while adding custom device “/dev/video0”: not a device node.

  1. Giving privileged access and mounting /dev to access all the devices: docker run -it --privileged -v /dev:/dev ...
    When I list the video devices in the container, I find nothing. When using the second option, there’s a directory /dev/video0/ instead of a video device.

I also tried a combination of both solutions (device with privileged mode and device with -v, etc.) but none of them worked. I’m not sure what I’m doing wrong. Do I have to run it with sudo or give docker the permission to access /dev somehow?