dockerserial-portvirtualttysocat

Docker container gives IO error when accessing psedo tty using socat


I am trying to connect serial ports from docker container. My host machine has two serial ports. One of them is created using socat. Serial ports: ttyS0, ttyV2

ttyV2 is created with following socat command.

socat PTY,link=/dev/ttyV2,waitslave tcp:192.168.1.102:101 &

I can reach both serial ports in my host machine. I created a docker container with following command.

 docker run -d --name serial_devices --device=/dev/ttyV2 --device=/dev/ttyS0 empty

Then attached the container with;

docker exec -it serial_devices /bin/bash

I can see devices in my container sucessfully. However serial ports created with socat give IO error. Serial ports error

I also tried with minicom it gives same error.

root@52ed12a3d7dc:/# minicom
minicom: cannot open /dev/ttyV2: Input/output error

I tried different settings of socat and docker however could not find the solution. Please can you help me debug this error and find solution?

Here is my Dockerfile

FROM ubuntu:latest
RUN apt-get update
RUN apt-get install minicom -y

ENTRYPOINT ["tail", "-f", "/dev/null"]

Solution

  • Try using the volume flag for the virtual port instead of the device flag.

    Example given:

    docker run -d --name serial_devices --volume=/dev/ttyV2:/dev/ttyV2 --device=/dev/ttyS0 empty