Symlink not working after reconnect of device

I want to use a serial USB device in a Docker container. Unfortunately, the USB device sometimes reconnects. The device name then changes from ttyUSB1 to ttyUSB2.

To compensate for this, I’m using a symbolic link: ttyUSB_DEVICE1

When the container starts, ttyUSB_DEVICE1 works correctly.

crw-rw---- 1 root dialout 188, 1 Nov 19 16:08 /dev/ttyUSB1
lrwxrwxrwx 1 root root 7 Nov 19 16:08 /dev/ttyUSB_DEVICE1 → ttyUSB1

After a reconnect, the device is unreachable within the container.

crw-rw---- 1 root dialout 188, 2 Nov 13 08:44 /dev/ttyUSB2
lrwxrwxrwx 1 root root 7 Nov 13 08:44 /dev/ttyUSB_DEVICE1 → ttyUSB2

I expected Docker to use the symbolic link that points to ttyUSB2 after reconnecting. Unfortunately, it doesn’t.

I have to reset the USB device so it’s called ttyUSB1 again.

Does anyone know a solution to this problem other than restarting the Docker container after reconnecting?

Docker uses the symlinks only to find the actual file. If it mounts the symlink into the container, processes in the container could not find the target file. If the process in the container can work with symlinks you could try mounting the entire /dev, but otherwise, I think you would always need to restart.

Thanks for this information. I’ve read a lot of topics about Docker and symlinks but this point wasn’t mentioned. Mounting the entire /DEV is a good hint and should work for me.