Trouble exposing devices in Sysbox containers with Docker's `--volume` option
Nobody has claimed this yet.
- Dominant language
- Shell
- Stars
- 3.9k
- Forks
- 230
- Avg merge
- 7h 48m
- Merged PRs (30d)
- 3
Description
My current setup with jenkins/docker is:
- Ubuntu host machine with docker installed
- Jenkins running on the host Ubuntu system as a docker container with
/var/run/docker.sockmounted into it via --volumes - Jenkins controller running builds inside Ubuntu-based docker containers with some additional tools installed on them, such as a python package called "usbhub", along with some runtime args:
args '--group-add=46 --device-cgroup-rule="c 189:* rmw" --volume /dev/bus/usb:/dev/bus/usb(189 being the usb major number)
And with this setup, I'm able run things likeusbhub idand have it successfully identify the connected usb hub:
+ usbhub id
Hub Key : 624C (0)
MPN : CRZRYC
Revision : 2
Serial : 682719FFFEA6624C
USB Path : 1-123
Now when I try to instead run it as a sysbox container by replacing -v /var/run/docker.sock:/var/run/docker.sock with runtime=sysbox-runc and manually starting docker up inside the jenkins sysbox container with a docker exec call, I'm able to run docker commands properly the same way I was able to when mounting the socket directly into a normal docker container, but I get the following I/O error inside the build (Ubuntu) container when trying to communicate with my external usb device
*this is with /dev/bus/usb mounted into both the jenkins sysbox container from host as well as into the ubuntu build container
+ usbhub id
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/capablerobot_usbhub/i2c.py", line 164, in read_i2c_block_data
length = self.hub.handle.ctrl_transfer(REQ_OUT+1, self.CMD_I2C_WRITE, cmd, 0, [register], timeout=self.timeout)
File "/usr/local/lib/python3.8/dist-packages/usb/core.py", line 1071, in ctrl_transfer
self._ctx.managed_open()
File "/usr/local/lib/python3.8/dist-packages/usb/core.py", line 113, in wrapper
return f(self, *args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/usb/core.py", line 131, in managed_open
self.handle = self.backend.open_device(self.dev)
File "/usr/local/lib/python3.8/dist-packages/usb/backend/libusb1.py", line 804, in open_device
return _DeviceHandle(dev)
File "/usr/local/lib/python3.8/dist-packages/usb/backend/libusb1.py", line 652, in __init__
_check(_lib.libusb_open(self.devid, byref(self.handle)))
File "/usr/local/lib/python3.8/dist-packages/usb/backend/libusb1.py", line 604, in _check
raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 5] Input/Output Error
@rodnymolina found a workaround using --device=/dev/bus/usb/001 instead of --volume /dev/bus/usb:/dev/bus/usb and running sudo chmod 666 /dev/bus/usb/001/001 and sudo chmod 666 /dev/bus/usb/001/002 for both the "nested" usb device directories in the host system before running the sysbox container. The problem with this is that the target devices need to be power cycled during multiple stages in the CI runs and come up in different modes as a "different device" at different times during the build, so being able to specify a parent directory under which they will all exist and reappear inside of is pretty necessary for my use case.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the nested Jenkins, Sysbox, Docker, and Ubuntu build-container setup using the /dev/bus/usb volume mount and the usbhub id command. Compare it with the reported --device=/dev/bus/usb/001 workaround and observe behavior after devices are power cycled and reappear. Done means USB devices can be accessed through the parent directory without the reported libusb I/O error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, python
- Domain
- devops, infrastructure
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100