Skip to content

Commit 170333a

Browse files
author
Piotr Stankiewicz
committed
Add a manual on using USB/IP in DD
Signed-off-by: Piotr Stankiewicz <[email protected]>
1 parent 95cb86f commit 170333a

File tree

1 file changed

+146
-0
lines changed
  • content/manuals/desktop/features

1 file changed

+146
-0
lines changed
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
---
2+
title: Using USB/IP with Docker Desktop
3+
linkTitle: USB/IP support
4+
weight: 80
5+
description: How to use USB/IP in Docker Desktop
6+
keywords: usb, usbip, docker desktop, macos, windows, linux
7+
toc_max: 3
8+
aliases:
9+
- /desktop/usbip/
10+
params:
11+
sidebar:
12+
badge:
13+
color: green
14+
text: New
15+
---
16+
17+
{{ < introduced desktop 4.35.0 "../../../../desktop/release-notes.md#4350" > }}
18+
19+
> [!NOTE]
20+
>
21+
> Available on Docker Desktop for Mac, Linux, and Windows with the Hyper-V backend.
22+
23+
USB/IP enables you to share USB devices over the network, which can then be accessed from within Docker containers. This page focuses on sharing USB devices connected to the machine you run Docker Desktop on.
24+
25+
## Setup and use
26+
27+
### Step one: Run a USB/IP server
28+
29+
To use USB/IP, you need to run a USB/IP server. For this guide, the implementation provided by [jiegec/usbip](https://github.com/jiegec/usbip) will be used.
30+
31+
1. Clone the repository.
32+
33+
```console
34+
$ git clone https://github.com/jiegec/usbip
35+
$ cd usbip
36+
```
37+
38+
2. Run the emulated Human Interface Device (HID) device example.
39+
40+
```console
41+
$ env RUST_LOG=info cargo run --example hid_keyboard
42+
```
43+
44+
### Step two: Start a privileged Docker container
45+
46+
To attach the USB device, start a privileged Docker container with the PID namespace set to `host`:
47+
48+
```console
49+
$ docker run --rm -it --privileged --pid=host alpine
50+
```
51+
52+
### Step three: Enter the mount namespace of PID 1
53+
54+
Inside the container, enter the mount namespace of the `init` process to gain access to the pre-installed USB/IP tools:
55+
56+
```console
57+
$ nsenter -t 1 -m
58+
```
59+
60+
### Step four: Use USB/IP tools
61+
62+
Now you can use the USB/IP tools as you would on any other system:
63+
64+
#### List USB devices
65+
66+
To list exportable USB devices from the host:
67+
68+
```console
69+
$ usbip list -r host.docker.internal
70+
```
71+
72+
Expected output:
73+
74+
```console
75+
Exportable USB devices
76+
======================
77+
- host.docker.internal
78+
0-0-0: unknown vendor : unknown product (0000:0000)
79+
: /sys/bus/0/0/0
80+
: (Defined at Interface level) (00/00/00)
81+
: 0 - unknown class / unknown subclass / unknown protocol (03/00/00)
82+
```
83+
84+
#### Attach a USB device
85+
86+
To attach a specific USB device, or the emulated keyboard in this case:
87+
88+
```console
89+
$ usbip attach -r host.docker.internal -d 0-0-0
90+
```
91+
92+
#### Verify device attachment
93+
94+
After attaching the emulated keyboard, check the `/dev/input` directory for the device node:
95+
96+
```console
97+
$ ls /dev/input/
98+
```
99+
100+
Example output:
101+
102+
```console
103+
event0 mice
104+
```
105+
106+
### Step five: Use the attached device in another container
107+
108+
While the initial container remains running to keep the USB device operational, you can access the attached device from another container. For example:
109+
110+
1. Start a new container with the attached device.
111+
112+
```console
113+
$ docker run --rm -it --device "/dev/input/event0" alpine
114+
```
115+
116+
2. Install a tool like `evtest` to test the emulated keyboard.
117+
118+
```console
119+
$ apk add evtest
120+
$ evtest /dev/input/event0
121+
```
122+
123+
3. Interact with the device, and observe the output.
124+
125+
Example output:
126+
127+
```console
128+
Input driver version is 1.0.1
129+
Input device ID: bus 0x3 vendor 0x0 product 0x0 version 0x111
130+
...
131+
Properties:
132+
Testing ... (interrupt to exit)
133+
Event: time 1717575532.881540, type 4 (EV_MSC), code 4 (MSC_SCAN), value 7001e
134+
Event: time 1717575532.881540, type 1 (EV_KEY), code 2 (KEY_1), value 1
135+
Event: time 1717575532.881540, -------------- SYN_REPORT ------------
136+
...
137+
```
138+
139+
### Notes
140+
141+
> [!IMPORTANT]
142+
>
143+
> The initial container must remain running to maintain the connection to the USB device. Exiting the container will stop the device from working.
144+
145+
- You can repeat the following process to attach and use additional USB devices as needed.
146+
- The Docker Desktop VM kernel image comes pre-configured with drivers for many common USB devices, but Docker can't guarantee every possible USB device will work with this setup.

0 commit comments

Comments
 (0)