Skip to content

Commit a54de63

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 a54de63

File tree

2 files changed

+146
-2
lines changed

2 files changed

+146
-2
lines changed
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
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. You can repeat the following process to attach and use additional USB devices as needed.
24+
25+
> [!NOTE]
26+
>
27+
> 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.
28+
29+
## Setup and use
30+
31+
### Step one: Run a USB/IP server
32+
33+
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.
34+
35+
1. Clone the repository.
36+
37+
```console
38+
$ git clone https://github.com/jiegec/usbip
39+
$ cd usbip
40+
```
41+
42+
2. Run the emulated Human Interface Device (HID) device example.
43+
44+
```console
45+
$ env RUST_LOG=info cargo run --example hid_keyboard
46+
```
47+
48+
### Step two: Start a privileged Docker container
49+
50+
To attach the USB device, start a privileged Docker container with the PID namespace set to `host`:
51+
52+
```console
53+
$ docker run --rm -it --privileged --pid=host alpine
54+
```
55+
56+
### Step three: Enter the mount namespace of PID 1
57+
58+
Inside the container, enter the mount namespace of the `init` process to gain access to the pre-installed USB/IP tools:
59+
60+
```console
61+
$ nsenter -t 1 -m
62+
```
63+
64+
### Step four: Use USB/IP tools
65+
66+
Now you can use the USB/IP tools as you would on any other system:
67+
68+
#### List USB devices
69+
70+
To list exportable USB devices from the host:
71+
72+
```console
73+
$ usbip list -r host.docker.internal
74+
```
75+
76+
Expected output:
77+
78+
```console
79+
Exportable USB devices
80+
======================
81+
- host.docker.internal
82+
0-0-0: unknown vendor : unknown product (0000:0000)
83+
: /sys/bus/0/0/0
84+
: (Defined at Interface level) (00/00/00)
85+
: 0 - unknown class / unknown subclass / unknown protocol (03/00/00)
86+
```
87+
88+
#### Attach a USB device
89+
90+
To attach a specific USB device, or the emulated keyboard in this case:
91+
92+
```console
93+
$ usbip attach -r host.docker.internal -d 0-0-0
94+
```
95+
96+
#### Verify device attachment
97+
98+
After attaching the emulated keyboard, check the `/dev/input` directory for the device node:
99+
100+
```console
101+
$ ls /dev/input/
102+
```
103+
104+
Example output:
105+
106+
```console
107+
event0 mice
108+
```
109+
110+
### Step five: Use the attached device in another container
111+
112+
While the initial container remains running to keep the USB device operational, you can access the attached device from another container. For example:
113+
114+
1. Start a new container with the attached device.
115+
116+
```console
117+
$ docker run --rm -it --device "/dev/input/event0" alpine
118+
```
119+
120+
2. Install a tool like `evtest` to test the emulated keyboard.
121+
122+
```console
123+
$ apk add evtest
124+
$ evtest /dev/input/event0
125+
```
126+
127+
3. Interact with the device, and observe the output.
128+
129+
Example output:
130+
131+
```console
132+
Input driver version is 1.0.1
133+
Input device ID: bus 0x3 vendor 0x0 product 0x0 version 0x111
134+
...
135+
Properties:
136+
Testing ... (interrupt to exit)
137+
Event: time 1717575532.881540, type 4 (EV_MSC), code 4 (MSC_SCAN), value 7001e
138+
Event: time 1717575532.881540, type 1 (EV_KEY), code 2 (KEY_1), value 1
139+
Event: time 1717575532.881540, -------------- SYN_REPORT ------------
140+
...
141+
```
142+
143+
> [!IMPORTANT]
144+
>
145+
> The initial container must remain running to maintain the connection to the USB device. Exiting the container will stop the device from working.

content/manuals/desktop/troubleshoot-and-support/faqs/general.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ For more information and examples, see [how to connect from a container to a ser
6363

6464
### Can I pass through a USB device to a container?
6565

66-
It is not possible to pass through a USB device (or a
67-
serial port) to a container as it requires support at the hypervisor level.
66+
Docker Desktop does not support direct USB device passthrough. However, you can use USB over IP to connect common USB devices to the Docker Desktop VM and in turn be forwarded to a container. For more details, see [Using USB/IP with Docker Desktop](/manuals/desktop/features/usbip.md).
6867

6968
### How do I run Docker Desktop without administrator privileges?
7069

0 commit comments

Comments
 (0)