Is it possible to expose a USB device to an LXC/Docker container?

后端 未结 3 2121
青春惊慌失措
青春惊慌失措 2021-02-13 18:20

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)

相关标签:
3条回答
  • 2021-02-13 18:47

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

    0 讨论(0)
  • 2021-02-13 18:58

    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.

    0 讨论(0)
  • 2021-02-13 19:01

    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").

    0 讨论(0)
提交回复
热议问题