Docker container can't see a serial port devic

2020-02-26 00:37发布

I'm trying to run a Docker container with access to a serial port on the host.

Here is what I did:

  • I used a Mac
  • Installed drivers on the host (http://www.prolific.com.tw/US/ShowProduct.aspx?p_id=229&pcid=41)
  • Plugged in the device
  • Ran ls /dev/t* that returned /dev/tty.usbserial - so it worked
  • Ran the container, docker run -it --privileged -v /dev:/dev node:4.4.0 /bin/bash, and then ls /dev/t* inside the container which didn't return the /dev/tty.usbserial device...

I played a lot with different variations of parameters, but I haven't found the working one :)

Also the --device flag is not suitable for me since the device might be reconnected and the name could differ from /dev/tty.usbserial.

2条回答
叛逆
2楼-- · 2020-02-26 01:05

As pointed by @pgayvallet on GitHub:

As the daemon runs inside a VM in Docker Desktop, it is not possible to actually share a mac host device with the container inside the VM, and this will most definitely never be possible.

查看更多
欢心
3楼-- · 2020-02-26 01:07

You can check if the script described in "Notification of new USB devices in docker container" (from Guido Diepen -- gdiepen) can help.

He too runs his container with the --privileged argument to allow it to access the devices. And he mounts the host directory /dev/bus/usb to the /dev/bus/usb directory within the container with the argument -v /dev/bus/usb:/dev/bus/usb when starting said container.

The script uses both inotifywait and lsusb to wait for devices to be (un)plugged and check if it was the device we are interested in.

The inotifywait will keep on listening to inodes create/delete events under the dev/bus/usb directory and will execute commands whenever an inode corresponding to a relevant device has been just created.

See also, once you have detected an plugged USB device, How to get Bus and Device relationship for a /dev/ttyUSB (not related to Docker, but still relevant).

查看更多
登录 后发表回答