2

I need to have acces to windows com port(COM3) form docker linux contianer: I tried like this:

docker run -d --name test_com_port -p 8090:80 --device=/dev/ttyACM14 --restart always test_com_port

docker run -d --name test_com_port -p 8090:80 –-device=COM3:/dev/ttyS2
 --restart always test_com_port

docker run -d --name test_com_port -p 8090:80 –-device=//./COM3:/dev/ttyS2
 --restart always test_com_port

but don't have any results. Also I visited microsoft tutorial but it is only for windows containers. Maybe some one have any solutions how to solve it?

  • have you found a solution? i think there is some evolution, but I'm still working on it https://learn.microsoft.com/en-us/windows/wsl/connect-usb – will.mendil Jun 24 '22 at 18:09

1 Answers1

1

hey there I was successfully able to map a windows serial device to a docker container, it was a long and tedious task but in the end I was successful. Any who has access to windows 10 with support for WSL 2 can follow these steps:

1.) Install WSL 2 with Ubuntu distro as it's easier to work with.

2.) On the windows host machine install this software called usbipd through command winget install usbipd for more information use this link

3.)Now we have to configure a few things in the Ubuntu distro so that the interfacing happens for that you will have to follow this link

4.)Once that is done you can now mount the device, before we start the mounting process make sure to plug-in the device to the windows host

5.)Before mounting you can check the list of available devices with usbipd wsl list. You will be able to see all the serial devices connected and now you can interface or mount or attach using the command usbipd wsl attach --busid=<BUSID>

6.)Once the device is attached you can open the wsl Ububtu use the command lsusb to check all available serial devices which communicate over USB.

7.)Now the final step is to mount the device to docker container with command --device /dev/<available port>; ex doecker run -d --device=/dev/<available ports from liunx ubuntu distro> <container>

Harshith Yadav
  • 106
  • 1
  • 9
  • 1
    could you precise the value of ``? In my wsl2 Ubuntu `lsusb` gives `Bus 001 Device 003` so I enter `--device dev/bus/usb/001/003` for my docker container? – Antoine Nguyen Feb 20 '23 at 20:09
  • @AntoineNguyen, in linux pc the usb to ttl converter will be displayed as **ttyUSB0 or ttyUSB1** etc. you can view this by first doing `cd /dev` then `ls` to view, when device is not connected the options ttyUSB0 or ttyUSB1 will not appear on screen there will be plenty of other things like **ttyS1, ttyS2 etc**, when you connect the device **ttyUSB0 or ttyUSB1** etc , will appear. that time use the command `--device /dev/ttyUSB0:/dev/ttyUSB0` etc – Harshith Yadav Feb 23 '23 at 12:25
  • @Harshith Yadav I can use usbipd and successfully attached. However my Linux only create /dev/ttyS0 ~ ttyS3. There is no ttyUSB11 or ttyS11 (My serial port in Win 11 is COM11). Any idea how to fix this? – Jackie Yeh Jun 21 '23 at 02:35