I have a need to share specific devices from /dev
on my host Linux machine with my docker containers.
The --privileged
flag works for sharing any devices in /dev
that are present at the time docker run
is called, but any subsequently added or removed devices do not propagate into the container.
I tried docker run -v=/dev:/dev ...
but that ended up screwing with the permissions and ownership of files like /dev/pts, leading to the host machine to not be able to create new psuedo-terminals.
I also tried the --device
flag, but that doesn't allow you to share a device that doesn't yet exist.
Finally, I tried sharing volumes for devices like -v=/dev/video0:/dev/video0
but if /dev/video0 doesn't exist before run, docker creates a directory there and a webcam will not take /dev/video0 when plugged in.
Is there any better way to get this supported functionality?
You are looking check the flag --device
--device=[]
Add a host device to the container (e.g. --device=/dev/sdc:/dev/xvdc:rwm)
Have a nice day!