Hello,
I’m not sure if this question was already asked, if so please point me to the answer. A quick search did not provide any meaningful answers on my side.
This question is about Torizon OS / the concept of developing embedded software in containers.
Let’s assume the requirement is that the user can plug in a printer in the end-device or leave the printer away. The application, on Torizon running inside a docker-container does only see the printer if it was plugged in on boot. If the container is started and the printer is plugged in after start it never appears in docker container.
I tried mounting the whole /dev as a volume as well as a specific device (docker run -d and -v)
Solutions I was thinking of:
- privileged
- With that it works, but for obvious reasons we don’t want to go with this solution.
- udev to the rescue
- Use a udev rule and restart the container when the printer is plugged in.
- The application would be killed ungraceful and restarted.
- This needs to sit in the torizon-core base OS (mixing application/hardware/kernel-stuff).
- device-cgroup-rule
- I found this hint on your “How to Use GPIO on Torizon OS” article
- On docker documentation they talk about having a udev rule with executing ‘mknod’ inside the container
- docker run | Docker Docs
- Having still the need for udev for ‘mknod’ means still a workaround to me.
So back to the question: What way do you recomment of mounting a pluggable USB device into a container. I want to be able to handle it from my application if it is there or not, so that I don’t have to mix application development with the base Torizon OS.
Thanks in advnace for your answer!
Philippe
Edit: We tried out 3. and it worked! However: Is there really no simpler solution? Especially one that does not need udev to be involved . Maybe podman would have a solution
?
We added in docker-compose.yml:
device_cgroup_rules:
- 'c 180:* rwm'
Then after connecting the USB printer:
docker exec torizon-climateprodtestapp-debug-1 mkdir /dev/usb
docker exec torizon-climateprodtestapp-debug-1 mknod /dev/usb/lp0 c 180 0
docker exec torizon-climateprodtestapp-debug-1 chown root:lp /dev/usb/lp0
docker exec torizon-climateprodtestapp-debug-1 chmod 660 /dev/usb/lp0