-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Add a manual on using USB/IP in DD #21533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| --- | ||
| title: Using USB/IP with Docker Desktop | ||
| linkTitle: USB/IP support | ||
| weight: 80 | ||
| description: How to use USB/IP in Docker Desktop | ||
| keywords: usb, usbip, docker desktop, macos, windows, linux | ||
| toc_max: 3 | ||
| aliases: | ||
| - /desktop/usbip/ | ||
| params: | ||
| sidebar: | ||
| badge: | ||
| color: green | ||
| text: New | ||
| --- | ||
|
|
||
aevesdocker marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| {{< introduced desktop 4.35.0 "../../desktop/release-notes.md#4350" >}} | ||
|
|
||
| > [!NOTE] | ||
| > | ||
| > Available on Docker Desktop for Mac, Linux, and Windows with the Hyper-V backend. | ||
|
|
||
| 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. | ||
|
|
||
| > [!NOTE] | ||
| > | ||
| > 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. | ||
|
|
||
| ## Setup and use | ||
|
|
||
| ### Step one: Run a USB/IP server | ||
|
|
||
| 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. | ||
|
|
||
| 1. Clone the repository. | ||
|
|
||
| ```console | ||
| $ git clone https://github.com/jiegec/usbip | ||
| $ cd usbip | ||
| ``` | ||
|
|
||
| 2. Run the emulated Human Interface Device (HID) device example. | ||
|
|
||
| ```console | ||
| $ env RUST_LOG=info cargo run --example hid_keyboard | ||
| ``` | ||
|
|
||
| ### Step two: Start a privileged Docker container | ||
|
|
||
| To attach the USB device, start a privileged Docker container with the PID namespace set to `host`: | ||
|
|
||
| ```console | ||
| $ docker run --rm -it --privileged --pid=host alpine | ||
| ``` | ||
|
|
||
| ### Step three: Enter the mount namespace of PID 1 | ||
|
Check warning on line 56 in content/manuals/desktop/features/usbip.md
|
||
|
|
||
| Inside the container, enter the mount namespace of the `init` process to gain access to the pre-installed USB/IP tools: | ||
|
|
||
| ```console | ||
| $ nsenter -t 1 -m | ||
| ``` | ||
|
|
||
| ### Step four: Use USB/IP tools | ||
|
|
||
| Now you can use the USB/IP tools as you would on any other system: | ||
|
|
||
| #### List USB devices | ||
|
|
||
| To list exportable USB devices from the host: | ||
|
|
||
| ```console | ||
| $ usbip list -r host.docker.internal | ||
| ``` | ||
|
|
||
| Expected output: | ||
|
|
||
| ```console | ||
| Exportable USB devices | ||
| ====================== | ||
| - host.docker.internal | ||
| 0-0-0: unknown vendor : unknown product (0000:0000) | ||
| : /sys/bus/0/0/0 | ||
| : (Defined at Interface level) (00/00/00) | ||
| : 0 - unknown class / unknown subclass / unknown protocol (03/00/00) | ||
| ``` | ||
|
|
||
| #### Attach a USB device | ||
|
|
||
| To attach a specific USB device, or the emulated keyboard in this case: | ||
|
|
||
| ```console | ||
| $ usbip attach -r host.docker.internal -d 0-0-0 | ||
| ``` | ||
|
|
||
| #### Verify device attachment | ||
|
|
||
| After attaching the emulated keyboard, check the `/dev/input` directory for the device node: | ||
|
|
||
| ```console | ||
| $ ls /dev/input/ | ||
| ``` | ||
|
|
||
| Example output: | ||
|
|
||
| ```console | ||
| event0 mice | ||
| ``` | ||
|
|
||
| ### Step five: Use the attached device in another container | ||
|
Check warning on line 110 in content/manuals/desktop/features/usbip.md
|
||
|
|
||
| While the initial container remains running to keep the USB device operational, you can access the attached device from another container. For example: | ||
|
|
||
| 1. Start a new container with the attached device. | ||
|
|
||
| ```console | ||
| $ docker run --rm -it --device "/dev/input/event0" alpine | ||
| ``` | ||
|
|
||
| 2. Install a tool like `evtest` to test the emulated keyboard. | ||
|
|
||
| ```console | ||
| $ apk add evtest | ||
| $ evtest /dev/input/event0 | ||
| ``` | ||
|
|
||
| 3. Interact with the device, and observe the output. | ||
|
|
||
| Example output: | ||
|
|
||
| ```console | ||
| Input driver version is 1.0.1 | ||
| Input device ID: bus 0x3 vendor 0x0 product 0x0 version 0x111 | ||
| ... | ||
| Properties: | ||
| Testing ... (interrupt to exit) | ||
| Event: time 1717575532.881540, type 4 (EV_MSC), code 4 (MSC_SCAN), value 7001e | ||
| Event: time 1717575532.881540, type 1 (EV_KEY), code 2 (KEY_1), value 1 | ||
| Event: time 1717575532.881540, -------------- SYN_REPORT ------------ | ||
| ... | ||
| ``` | ||
|
|
||
| > [!IMPORTANT] | ||
| > | ||
| > The initial container must remain running to maintain the connection to the USB device. Exiting the container will stop the device from working. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.