When defining a device map like this in docker-compose.yml:
version: "3.8"
services:
app:
build: .
devices:
- /dev/video0:/dev/video0
If you start this container without /dev/video0 on your host system, the container will crash with the following error:
Error response from daemon: error gathering device information while adding custom device "/dev/video0": no such file or directory
No
No, these mounts can not be changed after startup.
Possible solution:
I would prefer to create a network outside docker-compose, so that we can control when it's available and when not.
Change the compose file so that all other services also use that network
I would create a script that looks to which devices are available, and then use dynamically use docker run --network YOUR_NETWORK and add --device for each device that you discovered that is available.
If you would like to change devices automatically, you can think of a script that watches if devices change, and then stop the running container and start a new one using the created script. Though this will cause a short downtime.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With