Skip to content

Commit 7779f49

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

File tree

1 file changed

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

1 file changed

+142
-0
lines changed
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
---
2+
title: USB/IP support in 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+
---
11+
12+
> [!NOTE]
13+
>
14+
> This guide applies to all Docker Desktop backends apart from WSL2.
15+
16+
# Using USB/IP with Docker Desktop
17+
18+
This guide explains how to use USB/IP in Docker Desktop. USB/IP enables you to share USB devices over the network, which can then be accessed from within Docker containers. This guide will specifically focus on sharing USB devices connected to the machine you run Docker Desktop on.
19+
20+
## Prerequsites
21+
22+
- Docker Desktop version 4.35 or higher installed and confugured to use a backend other than WSL2
23+
24+
## Steps to Use USB/IP
25+
26+
### 1. Run a USB/IP Server
27+
28+
To use USB/IP, you need to run a USB/IP server. For this guide, we'll use the implementation provided by [jiegec/usbip](https://github.com/jiegec/usbip). Follow these steps:
29+
30+
1. Clone the repository:
31+
32+
```bash
33+
git clone https://github.com/jiegec/usbip
34+
cd usbip
35+
```
36+
37+
2. Run the emulated HID (Human Interface Device) device example:
38+
39+
```bash
40+
env RUST_LOG=info cargo run --example hid_keyboard
41+
```
42+
43+
### 2. Start a Privileged Docker Container
44+
45+
To attach the USB device, start a privileged Docker container with the PID namespace set to `host`:
46+
47+
```bash
48+
docker run --rm -it --privileged --pid=host alpine
49+
```
50+
51+
### 3. Enter the Mount Namespace of the Init Process
52+
53+
Inside the container, enter the mount namespace of the `init` process to gain access to the pre-installed USB/IP tools:
54+
55+
```bash
56+
nsenter -t 1 -m
57+
```
58+
59+
### 4. Use USB/IP Tools
60+
61+
Now you can use the USB/IP tools as you would on any other system.
62+
63+
#### a. List USB Devices
64+
65+
To list exportable USB devices from the host:
66+
67+
```bash
68+
usbip list -r host.docker.internal
69+
```
70+
71+
Expected output:
72+
73+
```console
74+
Exportable USB devices
75+
======================
76+
- host.docker.internal
77+
0-0-0: unknown vendor : unknown product (0000:0000)
78+
: /sys/bus/0/0/0
79+
: (Defined at Interface level) (00/00/00)
80+
: 0 - unknown class / unknown subclass / unknown protocol (03/00/00)
81+
```
82+
83+
#### b. Attach a USB Device
84+
85+
To attach a specific USB device, or the emulated keyboard in our case:
86+
87+
```bash
88+
usbip attach -r host.docker.internal -d 0-0-0
89+
```
90+
91+
#### c. Verify Device Attachment
92+
93+
After attaching the emulated keyboard, check the `/dev/input` directory for the device node:
94+
95+
```bash
96+
ls /dev/input/
97+
```
98+
99+
Example output:
100+
101+
```console
102+
event0 mice
103+
```
104+
105+
### 5. Use the Attached Device in Another Container
106+
107+
While the initial container remains running (to keep the USB device operational), you can access the attached device in another container. For example:
108+
109+
1. Start a new container with the attached device:
110+
111+
```bash
112+
docker run --rm -it --device "/dev/input/event0" alpine
113+
```
114+
115+
2. Install a tool like `evtest` to test the emulated keyboard:
116+
117+
```bash
118+
apk add evtest
119+
evtest /dev/input/event0
120+
```
121+
122+
3. Interact with the device, and observe the output:
123+
124+
Example output:
125+
126+
```console
127+
Input driver version is 1.0.1
128+
Input device ID: bus 0x3 vendor 0x0 product 0x0 version 0x111
129+
...
130+
Properties:
131+
Testing ... (interrupt to exit)
132+
Event: time 1717575532.881540, type 4 (EV_MSC), code 4 (MSC_SCAN), value 7001e
133+
Event: time 1717575532.881540, type 1 (EV_KEY), code 2 (KEY_1), value 1
134+
Event: time 1717575532.881540, -------------- SYN_REPORT ------------
135+
...
136+
```
137+
138+
### Notes
139+
140+
- The initial container must remain running to maintain the connection to the USB device. Exiting the container will stop the device from working.
141+
- You can repeat the process to attach and use additional USB devices as needed.
142+
- The Docker Desktop VM kernel image comes pre-configured with drivers for many common USB devices, but we can not guarantee every possible USB device will work with this set up.

0 commit comments

Comments
 (0)