5

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.

reconbot
  • 5,138
  • 6
  • 45
  • 63

2 Answers2

4

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.

larsks
  • 277,717
  • 41
  • 399
  • 399
  • There is no VM with "Docker for Mac" – reconbot Dec 04 '16 at 16:30
  • 3
    There is! I encourage you to closely read [the documentation](https://blog.docker.com/2016/03/docker-for-mac-windows-beta/), especially the part that says, " Docker engine is running in an Alpine Linux distribution on top of an xhyve Virtual Machine on Mac OS X". Docker under OS X used to use VirtualBox, but has recently switched to xhyve, but in both cases it still runs in a Linux VM because that is the only platform on which Docker runs natively. – larsks Dec 04 '16 at 16:40
3

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

Penkey Suresh
  • 5,816
  • 3
  • 36
  • 55