docker --device works with absolute device path, fails with symlink docker --device works with absolute device path, fails with symlink docker docker

docker --device works with absolute device path, fails with symlink


From this discussion I concluded that if your docker run command is how you actually use it, you can do a workaround using the bash subsition below helped by the tool 'readlink':

docker run --rm -it \        --device=$(readlink -f /dev/mcc_daq) \        mcc_daq1

However if you use docker-compose like me, this workaround get's slightly more awkward because you would need to do some preparatory juggling with environment variables I guess.

One of the problems with this workaround is of course that if you replug your device the path will be invalid. So you would have to restart the container I guess..


I hit this too, and haven't found a clean solution. In my case, I was using the nut-upsd container, with a udev remap rule symlink shared into the container. My error was

+ chgrp -R nut /etc/nut /dev/bus/usbchgrp: /dev/bus/usb: No such file or directory

and it was clear that this directory was indeed empty, and devices were not going to load properly for upsd. I still haven't found a "clean" solution, but I have resorted to overriding the container's entrypoint, with a custom one that sets up the device properly, then starts the inner entrypoint.

#!/bin/sh -exDEVICE=$(lsusb | grep "{{ device_vendor_id }}:{{ device_product_id }}")BUS=$(echo "$DEVICE" | cut -d' ' -f 2)DEVICE=$(echo "$DEVICE" | cut -d' ' -f 4 | tr -d :)DEST="/dev/bus/usb/$BUS/$DEVICE"echo "Linking {{ device_symlink }} to $DEST"mkdir -p "/dev/bus/usb/$BUS"ln -s "/dev/{{ device_symlink }}" "$DEST"{{ service_main_entrypoint }} $@

In my case, you can see my usage of ansible variables, as this is configured using an ansible playbook.

I'm currently using this for nut-upsd as well as rtl433.