Exposing a TTY device in a docker container with docker for mac

倖福魔咒の 提交于 2019-12-11 08:42:06

问题


I'm trying to expose an Arduino that's plugged into my mac to a linux instance I'm running in Docker for Mac (no vm).

The Arduino exposes itself as /dev/tty.usbserialXXX. I'm using the node docker image which is based upon ubuntu.

The command I'm running is

$ docker run --rm -it -v `pwd`:/app --device /dev/tty.usbmodem1421 node bash
docker: Error response from daemon: linux runtime spec devices: error gathering device information while adding custom device "/dev/tty.usbmodem1421": lstat /dev/tty.usbmodem1421: no such file or directory.

If I try to use --privileged

$ docker run --rm -it -v `pwd`:/app --device /dev/tty.usbmodem1421 --privileged node bash
root@8f18fdbcf64d:/# ls /dev/tty.*
ls: cannot access /dev/tty.*: No such file or directory

Nothing is exposed!

I'm using this to expose serial devices to test serial drivers in linux.


回答1:


The problem here is largely that you're not running Docker on your mac. You're running a Linux VM on your Mac, inside which you're running Docker. This means that it's easy to expose the /dev tree inside the Linux VM to Docker, but less easy to expose devices from your Mac, absent some kind of support from the hypervisor.

Using the legacy "Docker Toolbox" for Mac, which is built around VirtualBox, it ought to be possible to assign a USB device to the VirtualBox host running Docker (which would in turn allow you to expose it to your Docker containers).

This GitHub issue talks about this particular situation and has links to helpful documentation.

I don't know if this sort of feature is currently available with the hypervisor used in the newer "Docker for Mac" package.




回答2:


The Arduino devise that is listed at /dev/tty.usbserialXXX could be a symlink to the device, and not the actual path. To read the symlink path try using

docker run --rm -it -v `pwd`:/app --device=/dev/$(readlink /dev/tty.usbmodem1421) node bash

There was an issue open for this some time back. Do check if it solves your problem



来源:https://stackoverflow.com/questions/40442284/exposing-a-tty-device-in-a-docker-container-with-docker-for-mac

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!