Skip to content
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

Sharing a USB camera with usbipd in a docker container #13940

Open
1 of 2 tasks
guillaumenibert opened this issue Feb 29, 2024 · 2 comments
Open
1 of 2 tasks

Sharing a USB camera with usbipd in a docker container #13940

guillaumenibert opened this issue Feb 29, 2024 · 2 comments

Comments

@guillaumenibert
Copy link

guillaumenibert commented Feb 29, 2024

Description

I am looking to share my USB camera to a docker container.

WSL kernel is compiled with USB Camera drivers based on version 5.15.133.1; Tutorial provided by @AgileDevArt available here: https://youtu.be/t_YnACEPmrM?feature=shared&t=183.

Using usbipd-win, I can attach my USB camera to the docker-desktop distro.

/dev/video0 is visible in the docker-desktop distro, but not in the container: when I do lsusb in my container, the camera is visible, but the output of ls /dev does not list video0.

Reproduce

Based on discussion dorssel/usbipd-win#315, I performed these steps:

  1. I recompiled the Linux kernel for WSL with camera driver support,
  2. then attached my camera to WSL using usbipd,
  3. tested the camera on the Ubuntu default WSL distribution with cheese: it works.
  4. /dev/video0 is visible in the docker-desktop distro.
  5. I tried this tip ubdipd and docker container dorssel/usbipd-win#315 (comment) from @NikLeberg :

Hi @salvatoreTorsello I use usbipd successfully to forward a USB device to a docker container. For that I had to map -v /dev:/dev and add --privileged so the container can access the devices. Depending on you device you have to install drivers for it in WSL2 thought.

Adapting it, I tried these configurations (docker compose file), with or without privileges, with or without the devices part,

...
privileged: true
volumes:
   - /dev:/dev
   - /run/desktop/dev:/dev
   - /run/desktop/dev/video0:/dev/video0

devices:
   - /dev:/dev
   - /run/desktop/dev:/dev
   - /dev/video0:/dev/video0
...

Expected behavior

I should see /dev/video0 in my container.

docker version

Client:
 Cloud integration: v1.0.35+desktop.11
 Version:           25.0.3
 API version:       1.44
 Go version:        go1.21.6
 Git commit:        4debf41
 Built:             Tue Feb  6 21:13:02 2024
 OS/Arch:           windows/amd64
 Context:           default

Server: Docker Desktop 4.28.0 (139021)
 Engine:
  Version:          25.0.3
  API version:      1.44 (minimum version 1.24)
  Go version:       go1.21.6
  Git commit:       f417435
  Built:            Tue Feb  6 21:14:25 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.28
  GitCommit:        ae07eda36dd25f8a1b98dfbf587313b99c0190bb
 runc:
  Version:          1.1.12
  GitCommit:        v1.1.12-0-g51d5e94
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

docker info

Client:
 Version:    25.0.3
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.12.1-desktop.4
    Path:     C:\Program Files\Docker\cli-plugins\docker-buildx.exe
  compose: Docker Compose (Docker Inc.)
    Version:  v2.24.6-desktop.1
    Path:     C:\Program Files\Docker\cli-plugins\docker-compose.exe
  debug: Get a shell into any image or container. (Docker Inc.)
    Version:  0.0.24
    Path:     C:\Program Files\Docker\cli-plugins\docker-debug.exe
  dev: Docker Dev Environments (Docker Inc.)
    Version:  v0.1.0
    Path:     C:\Program Files\Docker\cli-plugins\docker-dev.exe
  extension: Manages Docker extensions (Docker Inc.)
    Version:  v0.2.22
    Path:     C:\Program Files\Docker\cli-plugins\docker-extension.exe
  feedback: Provide feedback, right in your terminal! (Docker Inc.)
    Version:  v1.0.4
    Path:     C:\Program Files\Docker\cli-plugins\docker-feedback.exe
  init: Creates Docker-related starter files for your project (Docker Inc.)
    Version:  v1.0.1
    Path:     C:\Program Files\Docker\cli-plugins\docker-init.exe
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
    Version:  0.6.0
    Path:     C:\Program Files\Docker\cli-plugins\docker-sbom.exe
  scout: Docker Scout (Docker Inc.)
    Version:  v1.5.0
    Path:     C:\Program Files\Docker\cli-plugins\docker-scout.exe

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 4
 Server Version: 25.0.3
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: ae07eda36dd25f8a1b98dfbf587313b99c0190bb
 runc version: v1.1.12-0-g51d5e94
 init version: de40ad0
 Security Options:
  seccomp
   Profile: unconfined
 Kernel Version: 5.15.133.1-microsoft-standard-WSL2+
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 12
 Total Memory: 15.55GiB
 Name: docker-desktop
 ID: fe6b043c-0942-4f94-92d2-99904de9fcbe
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5555
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: No blkio throttle.read_bps_device support
WARNING: No blkio throttle.write_bps_device support
WARNING: No blkio throttle.read_iops_device support
WARNING: No blkio throttle.write_iops_device support
WARNING: daemon is not using the default seccomp profile

Diagnostics ID

DF60968E-0B48-4B08-B771-845E49E521A1/20240229140159

Additional Info

Copy of this post in the usbipd project discussions: dorssel/usbipd-win#879; @dorssel advised me to also post my problem to WSL's GitHub repository: microsoft/WSL#11230.

Windows version

Microsoft Windows [version 10.0.22631.3155]

WSL Version

2.0.14

Are you using WSL 1 or WSL 2?

  • WSL 2
  • WSL 1

I am interested in any advice, whether or not it concerns WSL, Docker Desktop for Windows or usbipd.

Best regards,

Guillaume Nibert

@steb6
Copy link

steb6 commented Mar 11, 2024

@guillaumenibert any updates on this?

@guillaumenibert
Copy link
Author

@guillaumenibert any updates on this?

I have tried again, and it seems that rebooting the computer has made /dev/video0 visible.
Unfortunately, despite the presence of /dev/video0 in the container I cannot access the device. I have tried :

  • setting the container to be privileged
  • adding my container user to the video group

It does not work.

The only solution I have found which works is to enter the docker-desktop system

wsl --distribution docker-desktop

and change the owner of /dev/video0 to one with UID:GID = 1000:1000

chown 1000:1000 /dev/video0

The container now has access to the host's camera.

Best regards,

Guillaume Nibert

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants