Docker - a way to give access to a host USB or serial device?
There are a couple of options. You can use the --device
flag that use can use to access USB devices without --privileged
mode:
docker run -t -i --device=/dev/ttyUSB0 ubuntu bash
Alternatively, assuming your USB device is available with drivers working, etc. on the host in /dev/bus/usb
, you can mount this in the container using privileged mode and the volumes option. For example:
docker run -t -i --privileged -v /dev/bus/usb:/dev/bus/usb ubuntu bash
Note that as the name implies, --privileged
is insecure and should be handled with care.
Access webcam using OpenCV (Python) in Docker?
The Dockerfile in the link you provided doesn't specify how opencv was installed, can you provide the Dockerfile you used? Or how you installed opencv?
VideoCapture(0) won't work if you install opencv via pip.
You're using --device=/dev/video0:/dev/video0
correctly.
Docker- Any way to provide multiple USB device Access (Not using --privilaged)?
Docker works with device
option as an array. So,
you can specify several devices also with device
option:
docker run -ti --device=/dev/ttyUSB4 --device=/dev/video0 --device=/dev/video4 ubuntu bash
In docker-compose is also possible:
docker-compose.yml
...
services:
myservice:
...
devices:
- "/dev/ttyUSB4:/dev/ttyUSB4"
- "/dev/video0:/dev/video0"
- "/dev/video4:/dev/video4"
There's another possibility giving linux capability, but it's unrecommended (dangerous like privileged mode) for production: FOWNER capability:
docker run -ti --cap-add=FOWNER ubuntu bash
Nevertheless, in kubernetes, for example, it's not enough and you need privileged mode.
Related Topics
How to Remove Only the First Occurrence of a Line in a File Using Sed
How to Determine the Process Memory Limit in Linux
Understanding Sendfile() and Splice()
Implementing Poll in a Linux Kernel Module
How to Load Jna Native Support Library Elasticsearch 6.X
How to Do Foreach *.Mp3 File Recursively in a Bash Script
Is There Any Shortcut to Reference the Path of the First Argument in a Mv Command
Any Porting Available of Backtrace for Uclibc
"Cannot Execute Binary File" When Trying to Run a Shell Script on Linux
Perf Stat Does Not Count Memory-Loads But Counts Memory-Stores
Check That There Are at Least Two Arguments Given in a Bash Script
How to Start Redis-Server on a Different Port Than the Default Port 6379 in Ubuntu
Gdb Break When Program Opens Specific File