I’m using a python application that access a USB device (pipsta printer) and executes a routine, it is running fine outside the container, but when it comes to the container it returns a error like this:
(File "usr/local/lib/python2.7/dist-packages/usb/backend/libusb0.py", line 386, in _check:
raise USBError(errmsg, ret)
USB.core.USBError: [Errno None] couldn't opendir(): No such a file or directory)
In my dockerfile I included all the python and usb relevant packages, I also moved the relevant files to /etc/udev/rules.d and restarted udev.
Would it be possible to show your Dockerfile so we could take a look? Perhaps a device file in /dev is not being correctly generated via udev.
Also, are you activating udev in the container? If not you should have one of the first lines run within it be udevd && udevadm trigger' which starts the udev daemon within the container, and then replays udev events which occurred in the host operating system so they are reflected in the container also.
I notice that you have 2 CMDs in this Dockerfile - only the 2nd CMD will have any effect, that CMD service udev restart will do nothing. From the docs - ‘There can only be one CMD instruction in a Dockerfile. If you list more than one CMD then only the last CMD will take effect.’
You should also run udevadm trigger so the host’s udev events are rerun after udev is restarted. So overall I suggest you remove the first CMD and make the second:-
CMD service udev restart && udevadm trigger && python V1.py
Though at this point it might be worth turning this into a script, ADDing the script and having the CMD call it
CMD service udev restart && udevadm trigger && python V1.py
And I get the following:
" File “/usr/local/lib/python2.7/dist-packages/usb/core.py”, line 1207, in find
return_interop._next(device_iter(k, v))
File “usr/local/lib/python2.7/dist-packages/usb/_interop.py”, line 60, in _next
retur next(iter)
File “/usr/local/lib/python2.7/dist-packages/usb/core.py”, line 1175, in device_iter
for dev in backend.enumerate_devices():
File “/usr/local/lib/python2.7/dist-packages/usb/backend/libusb0.py”, line 386, in enumerate_devices
_check(_lib.usb_find_busses())
File “/usr/local/lib/python2.7/dist-packages/usb/backend/libusb0.py”, line 380, in _check
raise USBError(errmsg, ret)
usb.core.USBError: [Errno None] couldn’t opendir(): No such file or directory"
Outside the container the application still runs just fine.
This is really strange, I think it is trying to look for USB file entries in an invalid location (a location which is no longer valid in recent kernels), however the libusb code clearly tries to check other locations first, specifically /dev/bus/usb so the error suggests that this directory isn’t getting populated.
Could you move the commands from the CMD into a script, and then run simply run a command to see if the directory has any contents?
#!/bin/bash
service udev restart
udevadm trigger
#python V1.py
echo "/dev/bus/usb contents:-"
ls -l /dev/bus/usb
echo "done!"
I’ve experimented locally and these files do get populated, so it’s quite possible the device isn’t getting recognised for some reason.
Also try replacing service udev restart in this script with udevd &, as far as I can tell they should do the same, but it won’t hurt to experiment with that too!
Let me know the output of the above and whether udevd & helps!
Could you give me the URL to the device experiencing this? I could have a look around inside for you if you’re ok with that + get a better idea of what’s going on there. Only admins and you have access to this page so don’t worry about it being public here though if would prefer it to remain private, click on the overlayed question mark in the bottom right hand corner of the page and send a message and we can discuss the issue there!
Could you try something quickly to see if it’s related to a potential issue with the source image - replace the FROM field with FROM resin/rpi-raspbian:wheezy (i.e. not specifying the more recent build)?
Sorry about the delay on my answer, I’ve been busy around others projects, I tried using Wheezy without specifying the version and I also tried to use Jessie both specifying the latest version and without specifying any version, I always get the same. Thank you for you engagement.