14

I have an embedded system development image contained in a Docker file. In order to flash the code I need to connect to the nodes via USB Serial (e.g. /dev/ttyACM0).

With Docker I used the new bind mount feature to (see https://github.com/dotcloud/docker/issues/111, -b or more recently the -v option) to expose the hosts devfs to the container. However, whenever I connect ("cat /d/ttyACM0", d is the bind mount to dev) to the device I get "operation not permitted". Is it possible to not only bind mount, but actually use character devices in the container?

Would it be maybe even possible to expose specific devs via udev rules?

Community
  • 1
  • 1
till
  • 570
  • 1
  • 6
  • 22

3 Answers3

5

The --device option now allows exposing a /dev to a container, for example:

docker run -t -i --device=/dev/ttyUSB0 ubuntu bash

(I found from this Stack Overflow answer.)

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
tuomassalo
  • 8,717
  • 6
  • 48
  • 50
  • Thanks – I copied the essential part here. I believe I answered at least part of the question ("Is it possible to not only bind mount but actually use character devices in the container?"). – tuomassalo Aug 03 '16 at 19:35
4

At the current moment, this is not possible with Docker. However, we are working on a 'privilege' mode that would allow a container to access devices like USB or GPU.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
creack
  • 116,210
  • 12
  • 97
  • 73
0

While not possible via Docker itself (see previous answer) using lxc-cgroup directly on the running container seems to do the trick for me:

sudo lxc-cgroup -n 0dd4c652d0740e5ddb6f80e6f2ec2c52dd6435b22c8114c000c58ca9703ebc62 devices.allow "c 166:* rwm"

166 stands for ttyACM, the device class.

The Docker id needs to be the complete one (via Docker inspect "ID").

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
till
  • 570
  • 1
  • 6
  • 22
  • Note that it is dangerous to rely on docker and LXC commands at the same time. While docker makes use of LXC, it might not in the future and no compatibility is guaranteed as far as I know. – qkrijger Jul 31 '13 at 17:01