I need to add USB device to an existing Docker container.
Can I update my container config to add a line like --device=/dev/bus/usb/001/004 ?
Thanks for your answer
As a general rule: no, if you need to change attached devices or volumes or networking or anything else, you need to stop and remove your container and restart it with new options.
This should be extremely routine, and you should set up your Docker containers so that you can stop, delete, and recreate them freely without losing anything (aside from service uptime).
Actually, at least for Linux, you can. You need to get the device major number, and then add it to devices.allow.
So, for example:
udevadm info -q property -n /dev/bus/usb/$BUS/$DEV | grep MAJOR
would return something like:
Now get the container ID:
The ID will be something like ‘79a934b19eb3’
So now pass it through:
echo ‘c 189:* rwm’ > /sys/fs/cgroup/devices/docker/79a934b19eb3*/devices.allow
I’ve scripted all this up, but this is just an example.