reconbot reconbot - 2 months ago 48
Linux Question

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

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

. I'm using the
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

$ 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.


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.