shackhaa.blogg.se

Socat redirect serial to usb
Socat redirect serial to usb













If you want to be more specific, you can use udevadm info -name= to find other parameters by which you can filter devices. This file adds new entry to your rules, basically saying: Every time tty device is plugged in - add or plugged out - remove run the provided script and pass some parameters. On ubuntu, you should create file /etc/udev/rules.d/les as superuser (sudo): ACTION="add", SUBSYSTEM="tty", RUN+="/usr/local/bin/docker_tty.sh 'added' '%E' '%M' '%m'" Some explanation about custom rules here and here on passing arguments. Now the idea is to add a script which would be run every time your USB device is plugged in or plugged out. You can run docker image allowing access to range of devices with specific major number, docker will add required rules for you in your host machine (this will run docker in detached mode, we will attach to it later): docker run -device-cgroup-rule='c 188:* rmw' -itd -name my_container ubuntu Run following command: $ ls -l /dev/ | grep ttyUSBĬrw-rw-rw- 1 root dialout 188, 0 Mar 1 18:23 ttyUSB0 #Example outputīased on the output you can see that the major group of tty devices is 188 in my case, so I will proceed with that. First of all, lets find cgroup properties of your USB device. Idea is to configure cgroup rules properly. Just follow the instruction line by line, all steps are explained The Safe and Proper way of accessing tty devices without -privileged mode Without doing this, any newly plugged or rebooting device after the container started, will get a new bus ID and will not be allowed access in the container. Then start your container like this: docker run -v /dev/bus:/dev/bus:ro -v /dev/serial:/dev/serial:ro -i -t -entrypoint /bin/bash debian:amd64 It may be different on your system than on mine: echo 'c 188:* rwm' > /sys/fs/cgroup/devices/docker/$A*/devices.allow It's a bit hard to paste, but in a nutshell, you need to get the major number for your character device and send that to cgroup:ġ88 is the major number of /dev/ttyUSB*, which you can get with 'ls -l'.

socat redirect serial to usb

See details here: Accessing USB Devices In Docker without using -privileged Using the cgroups approach is better in that respect and works on devices that get added after the container as started. Basically this allows the container to gain root on the host, which is usually not what you want. You could just use -v /dev:/dev but that's unsafe as it maps all the devices from your host into the container, including raw disk devices and so forth. You have to use cgroup devices.allow get around it. device works until your USB device gets unplugged/replugged and then it stops working.















Socat redirect serial to usb