1
1
# container-hotplug
2
2
3
- Hot-plug (and unplug) devices into a Docker container as they are (un)plugged.
3
+ Hot-plug (and unplug) devices into a container as they are (un)plugged.
4
4
5
5
## Description
6
6
@@ -18,32 +18,82 @@ It then interfaces directly with the container's cgroup to grant it access to th
18
18
To limit the devices the container can access, a _ root device_ is specified.
19
19
The container will receive access to any device descending from the root device.
20
20
This is particularly useful if the root device is set to a USB hub.
21
- However, since hubs are rarely interesting, it can be specified as "the parent of device X",
21
+ The hub can be specified directly, or it can be specified as "the parent of device X",
22
22
e.g., we can giving a container access to all devices connected to the same hub as an Arduino board.
23
23
24
24
Another concern is providing a container with well known paths for the devices.
25
25
On bare-metal systems this would usually be achieved with a ` SYMLINK ` directive in a udev rule.
26
26
This program tries to provide a similar functionality for containers, allowing you to specify symlinks for certain devices.
27
27
28
- This tool supports both cgroup v1 and v2.
28
+ ## Usage
29
29
30
- ## Example
30
+ This tool wraps ` runc ` command, with the additional hotplug feature. Therefore, it can be used as a drop in replace for
31
+ many container managers/orchestrators that makes use of runc as runtime. You need to ensure ` runc ` is available in your ` PATH `
32
+ so ` container-hotplug ` can find it.
31
33
32
- Give a container access to all devices connected to the same hub as a CW310 board .
34
+ It supports two annotations, ` org.lowrisc.hotplug.device ` and ` org.lowrisc.hotplug.symlinks ` .
33
35
34
- 1 . Find the USB VID and PID of the device using ` lsusb ` , for a CW310 that is ` 2b3e:c310 `
35
- 2 . Run (as root) the container using ` container-hotplug ` :
36
+ For Docker, you can specify an alternative runtime by [ changing /etc/docker/daemon.json] ( https://docs.docker.com/engine/alternative-runtimes/#youki ) :
37
+ ``` json
38
+ {
39
+ "runtimes" : {
40
+ "hotplug" : {
41
+ "path" : " /path/to/container-hotplug/binary"
42
+ }
43
+ }
44
+ }
36
45
```
37
- container- hotplug run \
38
- -d parent-of:usb:2b3e:c310 \
39
- -- -it ubuntu:22.04 bash
46
+ and use it by ` --runtime hotplug` and appropriate annotation, e.g.
47
+ ``` bash
48
+ sudo docker run --runtime hotplug -it --annotation org.lowrisc.hotplug.device=parent-of:usb:2b2e:c310 ubuntu:latest
40
49
```
41
50
42
- If you want symlinks to the ` tty ` devices created by interfaces 1 and 3 of the CW310, run:
51
+ For podman, you can specify the path directly, by:
52
+ ``` bash
53
+ sudo podman run --runtime /path/to/container-hotplug/binary -it --annotation org.lowrisc.hotplug.device=parent-of:usb:2b2e:c310 ubuntu:latest
43
54
```
44
- container-hotplug run \
45
- -d parent-of:usb:2b3e:c310 \
46
- -l usb:2b3e:c310:1=/dev/ttyACM_CW310_0 \
47
- -l usb:2b3e:c310:3=/dev/ttyACM_CW310_1 \
48
- -- -it ubuntu:22.04 bash
49
- ```
55
+
56
+ For containerd (e.g. when using kubernetes), you can ` /etc/containerd/config.toml ` to add:
57
+ ``` toml
58
+ [plugins ."io .containerd .grpc .v1 .cri" .containerd .runtimes .hotplug ]
59
+ runtime_type = " io.containerd.runc.v2"
60
+ pod_annotations = [" org.lowrisc.hotplug.*" ]
61
+
62
+ [plugins ."io .containerd .grpc .v1 .cri" .containerd .runtimes .hotplug .options ]
63
+ SystemdCgroup = true
64
+ BinaryName = " /path/to/container-hotplug/binary"
65
+ ```
66
+ this would allow you to use ` hotplug ` as handler in k8s, e.g. add a runtime class with
67
+ ``` yaml
68
+ apiVersion : node.k8s.io/v1
69
+ kind : RuntimeClass
70
+ metadata :
71
+ name : hotplug
72
+ handler : hotplug
73
+ ` ` `
74
+ and use it in pod with
75
+ ` ` ` yaml
76
+ apiVersion : v1
77
+ kind : Pod
78
+ metadata :
79
+ name : ubuntu
80
+ annotations :
81
+ org.lowrisc.hotplug.device : usb:0bda:5634
82
+ spec :
83
+ runtimeClassName : hotplug
84
+ containers :
85
+ - name : ubuntu
86
+ image : ubuntu:latest
87
+ stdin : true
88
+ tty : true
89
+ ` ` `
90
+
91
+ If you want symlinks to the ` tty` devices created by interfaces 1 and 3 of the CW310, add
92
+ ```
93
+ --annotation org.lowrisc.hotplug.symlinks=usb:2b3e:c310:1=/dev/ttyACM_CW310_0,usb:2b3e:c310:3=/dev/ttyACM_CW310_1
94
+ ```
95
+ to docker/podman command line or
96
+ ```
97
+ org.lowrisc.hotplug.symlinks: usb:2b3e:c310:1=/dev/ttyACM_CW310_0,usb:2b3e:c310:3=/dev/ttyACM_CW310_1
98
+ ```
99
+ to k8s config.
0 commit comments