title: docker --device works with absolute device path, fails with symlink
body: <p>I have a <a href="https://www.mccdaq.com/usb-data-acquisition/USB-2408-Series.aspx" rel="nofollow noreferrer">USB GPIO</a> device with some <a href="https://github.com/wjasper/Linux_Drivers" rel="nofollow noreferrer">3rd party drivers</a> that I want to interface with in a container. Compiles, works fine on host. Also compiles, works fine in the container if I pass <code>--device=/dev/bus/usb/001/$NUM</code> where $NUM is the autogenerated path when the device is plugged in; I presume udev is assigning this. However I want a deterministic bind point, so I modified the udev <a href="https://github.com/xkortex/mccdaq_dockerize/blob/master/61-mcc.rules#L2" rel="nofollow noreferrer">rules</a> to assign a symlink: </p>
  
  <pre><code>SUBSYSTEM=="usb", ATTR{idVendor}=="09db", 
  ATTR{idProduct}=="0075", MODE="0666", 
  TAG+="uaccess", TAG+="udev-acl", 
  SYMLINK+="mcc_daq"
  </code></pre>
  
  <p>And that gives me a symlink at <code>/dev/mcc_daq</code> to <code>/dev/bus/usb/whatever</code>. Still works fine on host. </p>
  
  <p>But, if I run with:</p>
  
  <pre><code>docker run --rm -it \
          --device=/dev/mcc_daq \
          mcc_daq1
  </code></pre>
  
  <p>I get </p>
  
  <pre><code>usb_device_find_USB_MCC: libusb_open failed.: No such file or directory 
  Failure, did not find a USB 2408 or 2408_2AO!
  </code></pre>
  
  <p>which is what the <a href="https://github.com/wjasper/Linux_Drivers/blob/master/USB/mcc-libusb/test-usb2408.c#L93" rel="nofollow noreferrer">test program spits out</a> when it can't find the device (uses <a href="http://libusb.sourceforge.net/api-1.0/group__desc.html" rel="nofollow noreferrer">libusb_get_device_descriptor</a>). </p>
  
  <p>When I run in the container <code>udevadm info -q all /dev/mcc_daq</code>, I get the same exact output as <code>udevadm info -q all /dev/bus/usb/001/004</code> when I start the container with <code>--device=/.../004</code>. However, if I pass in the symlink path to docker, I can't query the absolute path.  </p>
  
  <p>The udev output is more verbose on the host system, I'm not sure if this is part of the problem or expected behavior. My intuition is the lack of those extra entries means that libusb can find the device, but it can't find the vendor ID of the product. However, the fact that the udev output is the same in the container (regardless whether symlink or hard path) makes me question that. </p>
  
  <p><strong>Update</strong>: New fun fact: when I run strace on the test program, I find: </p>
  
  <pre><code>open("/dev/bus/usb/001/004", O_RDWR)    = -1 ENOENT (No such file or directory)
  </code></pre>
  
  <p>So that means the driver is looking for <code>../004</code>, even though I mounted <code>---device=/dev/mcc_daq</code>. I'm not sure where it's getting this information. </p>
  
  <p><strong>In short, I think using <code>docker run --device=/dev/symlink</code> does not introduce the same udev context as using the hard path, even though output of <code>udevadm info</code> is the same.</strong> </p>
  
  <p>Host: <code>udevadm info -q all /dev/mcc_daq</code> </p>
  
  <pre><code>P: /devices/pci0000:00/0000:00:14.0/usb1/1-8/1-8.2
  N: bus/usb/001/004
  S: mcc_daq
  E: BUSNUM=001
  E: DEVLINKS=/dev/mcc_daq
  E: DEVNAME=/dev/bus/usb/001/004
  E: DEVNUM=004
  E: DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-8/1-8.2
  E: DEVTYPE=usb_device
  E: DRIVER=usb
  E: ID_BUS=usb
  E: ID_FOR_SEAT=usb-pci-0000_00_14_0-usb-0_8_2
  E: ID_MODEL=USB-2408-2AO
  E: ID_MODEL_ENC=USB-2408-2AO
  E: ID_MODEL_ID=00fe
  E: ID_PATH=pci-0000:00:14.0-usb-0:8.2
  E: ID_PATH_TAG=pci-0000_00_14_0-usb-0_8_2
  E: ID_REVISION=0101
  E: ID_SERIAL=MCC_USB-2408-2AO_01DA523C
  E: ID_SERIAL_SHORT=01DA523C
  E: ID_USB_INTERFACES=:ffff00:
  E: ID_VENDOR=MCC
  E: ID_VENDOR_ENC=MCC
  E: ID_VENDOR_FROM_DATABASE=Measurement Computing Corp.
  E: ID_VENDOR_ID=09db
  E: MAJOR=189
  E: MINOR=3
  E: PRODUCT=9db/fe/101
  E: SUBSYSTEM=usb
  E: TAGS=:uaccess:seat:udev-acl:
  E: TYPE=255/255/0
  E: USEC_INITIALIZED=19197013
  </code></pre>
  
  <p>Docker: <code>udevadm info -q all /dev/mcc_daq</code> </p>
  
  <pre><code>P: /devices/pci0000:00/0000:00:14.0/usb1/1-8/1-8.2
  N: bus/usb/001/004
  E: BUSNUM=001
  E: DEVNAME=/dev/bus/usb/001/004
  E: DEVNUM=004
  E: DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-8/1-8.2
  E: DEVTYPE=usb_device
  E: DRIVER=usb
  E: MAJOR=189
  E: MINOR=3
  E: PRODUCT=9db/fe/101
  E: SUBSYSTEM=usb
  E: TYPE=255/255/0
  </code></pre>
  
  <p>Docker: <code>udevadm info -q all /dev/bus/usb/001/004</code></p>
  
  <pre><code>P: /devices/pci0000:00/0000:00:14.0/usb1/1-8/1-8.2
  N: bus/usb/001/004
  E: BUSNUM=001
  E: DEVNAME=/dev/bus/usb/001/004
  E: DEVNUM=004
  E: DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-8/1-8.2
  E: DEVTYPE=usb_device
  E: DRIVER=usb
  E: MAJOR=189
  E: MINOR=3
  E: PRODUCT=9db/fe/101
  E: SUBSYSTEM=usb
  E: TYPE=255/255/0
  </code></pre>