Styp
Styp

Reputation: 271

docker-compose device wildcard

I need to pass all video or audio or USB devices to a container.

devices:
  - "/dev/video*:/dev/video*"

This apparently doesn't work. But I the platform the container runs on, could have 2, 3 or more video sources and I need to pass all these into the docker container.

Anyone an idea, how to make this possible with docker-compose? I don't want to use 'priviledged' mode.

Thanks! Martin

Upvotes: 5

Views: 9844

Answers (1)

atline
atline

Reputation: 31654

You can map /dev to container, and add cgroups permission for the device.

If directly use docker command, see this

docker run -it --rm -v /dev:/dev --device-cgroup-rule='c *:* rmw' ubuntu:18.04 /bin/bash

You can change the first * in above command to major device number if you want to limit to some devices.

For compose, it seems just 2.3 can support this(I'm not sure why 3 not support, maybe need times), see this

version: "2.3"
services:
  backend:
     image: ubuntu:18.04
     device_cgroup_rules:
       - 'c *:* rmw'
     volumes:
       - /dev:/dev

Upvotes: 6

Related Questions