atline
atline

Reputation: 31574

How to escape colon when add device to docker container?

  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?

Upvotes: 4

Views: 2879

Answers (1)

atline
atline

Reputation: 31574

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.

Upvotes: 4

Related Questions