4
  1. This is ok to add device which by serial id:

    docker run -it --rm --device /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A101A9A7-if00-port0 -v /dev:/dev ubuntu /bin/bash
    
  2. This is not ok to add device which by serial path:

    docker run -it --rm --device /dev/serial/by-path/pci-0000:00:14.0-usb-0:8:1.0-port0 -v /dev:/dev ubuntu /bin/bash
    

    It reports error:

    invalid argument "/dev/serial/by-path/pci-0000:00:14.0-usb-0:8:1.0-port0" for "--device" flag: bad format for path: /dev/serial/by-path/pci-0000:00:14.0-usb-0:8:1.0-port0
    See 'docker run --help'.

    Same error if do escape string for : as next:

    docker run -it --rm --device /dev/serial/by-path/pci-0000\:00\:14.0-usb-0\:8\:1.0-port0 -v /dev:/dev ubuntu /bin/bash
    

As I know, for bind mount, we now could use something like --mount type=bind,source=/colon:path/test,destination=/data to handle it, see this.

So my question is: for --device, what could I do?

atline
  • 28,355
  • 16
  • 77
  • 113
  • Did you try to use single quotes around device name ? like this : ```docker run -it --rm --device '/dev/serial/by-path/pci-0000:00:14.0-usb-0:8:1.0-port0' -v /dev:/dev ubuntu /bin/bash``` – Flo May 28 '19 at 09:50
  • @Flo Not work with `''`, also not with `""` – atline May 28 '19 at 09:52
  • 2
    Ah! You're not alone, check last answer: https://github.com/moby/moby/issues/8604#issuecomment-451705509 I don't know if it's an open issue or not... – Flo May 28 '19 at 09:58
  • Seems no one handle that, half year ago. – atline May 28 '19 at 10:00

1 Answers1

4

Answer for myself, from this discussion:

It seems CLI not support escaping the colons, currently the only way is to make symbol link like next:

ln -s /dev/serial/by-path/pci-0000:00:14.0-usb-0:8:1.0-port0 /dev/serial/by-path/mydevice01
docker run -it --rm --device /dev/serial/by-path/mydevice01 -v /dev:/dev ubuntu /bin/bash

This is what I made workaround currently.

atline
  • 28,355
  • 16
  • 77
  • 113
  • 1
    Thanks for the answer, but the situation with docker is of course awful. So much for the tool which runs the industry... – pfalcon Jun 30 '21 at 21:19