Using socat to read data on host and transport to container

Hi,

Instead of reading DSMR P1 data directly by USB cable I am trying to transfer it by using an ethernetreader so I can put my computer somewhere else. Using Debian 11 and Portainer 2.6.3.

After installing a script mentioned on this page, (i.e. “socat -T60 pty,link=/dev/ttyUSB0,rawer,group-late=dialout,mode=660 tcp:192.168.188.7:23.,retry=forever,interval=30”) I am trying to pass that data through to a container.

On the host everything looks OK, data is present on ttyUSB0 and refreshed. Inside the container (IP 172.17.0.3 on host 192.168.188.5) I still have device /dev/ttyUSB0 as well as for host as container. But… no data. If I connect the datacable directly to the host, data inside the container is being read OK.

What am I missing? Or could I try next? Any ideas?

Docker puts a NAT between the host network and the container network. docker0 bridge uses source NAT for outbound traffic and destination NAT for inbound So, you’re trying to TCP (point-to-point) from the host across the NAT to the container. The host interface knows nothing on the other side of the NAT.

Your container will need to get an interface on the host network which you can do in a couple of ways - use the hosts’ interfaces or use a macvlan (gives the container an IP on the host network). Not sure which will work better for you, so grab a beer and enjoy your evening. :wink: