Search code examples
macosdockerusbwebcam

Accessing USB webcam hosted on OS X from a Docker container


Is it possible to access a USB camera (e.g Logitech c270) from a Docker container? The camera is connected to a Mac host via a USB port. Even when running the container with --privileged, i could not find the device (e.g /dev/video0 file does not exist).

Thanks


Solution

  • The default docker-machine creates a virtual machine with official boot2docker.iso. And this slim distro doesn't support USB video device. When you attach the USB device to the virtual machine, the kernel can't do anything without the right driver. So, you won't see any video capturing device, such as /dev/video0.

    TL;DR

    I've compiled a customized boot2docker.iso which ships uvcvideo driver. Use this one to create you docker machine.

    docker-machine create -d virtualbox --virtualbox-boot2docker-url https://github.com/Alexoner/boot2docker/releases/download/v17.06.0-ce-usb-rc5/boot2docker.iso default
    

    Then install the VirtualBox extension, attach the webcam device, you are good to go!

    Reference

    Attach webcam: https://www.virtualbox.org/manual/ch09.html#webcam-passthrough