Can't open camera by index on LXC container

The errors that you get, stem from the fact that your non-root user in the container (user account ubuntu) has no access to the /dev/video0 device. Because on the host this device belongs to group video and your desktop user on the host is a member of this video group (access allowed).

But when you add the /dev/video0 device into the container without specifying group information or file permissions, the default is to apply the group root (no access, unless you add sudo).

There are all sorts of workarounds but I think the cleaner solution is to specify a group to the /dev/video0 in the container so that the non-root account in the container can access the webcam freely.

If you want a quick workaround, you can just run the following command in the container that changes the permissions of the device to make it accessible to the non-root account. You may have to reapply the command when you reconnect the camera or restart the container.

sudo chown root:ubuntu /dev/video0

That’s what you are trying to do with this command. But The device already exists, which means that you have to remove it first, before adding it again where you specify the GID.

hany@hany-asus:~$ lxc config device add rosfoxy video0 unix-char path=/dev/video0 gid=1000
Error: The device already exists
hany@hany-asus:~$ lxc config device remove rosfoxy video0
hany@hany-asus:~$ lxc config device add rosfoxy video0 unix-char path=/dev/video0 gid=1000
2 Likes