Kindly take a note of each and every point I will be sending
I have two docker images one is of mysql headlessev-302-evmysqlcont and other is springboot application where its base image is debian-10.6 name is headlessev-302-projcont
these two images are in two containers but they are in same network
My host system is windows machine
one of my docker container is of debian based
5 . I have written docker-compose file to run my both containers for building i use docker-compose build and run i use docker-compose up
6.now my host system is connected to external vector hardware using usb now how can my docker container can detect that usb ?
7.use this information if required
Vector-Hardware
Vector Informatik GmbH
Port_#0001.Hub_#0002
This is my device instance path USB\VID_1248&PID_1001\5&271999B4&0&1
This is my hardware id USB\VID_1248&PID_1001&REV_0001
Docker file for mysql application
FROM mysql:latest
ENV MYSQL_ROOT_PASSWORD=âPASSWORDâ
COPY mysqlinit.sql /docker-entrypoint-initdb.d/
EXPOSE 3306
When running Docker on Windows, do you use Docker Desktop? That creates a Linux VM in which containers are usually run, so you need to attach the USB device to the VM, too.
Accessing external vector hardware in a Docker container is a bit like connecting your computer to a special tool.
Letâs understand with an example, Imagine you have a cool gadget outside your house, and you want to use it on your computer. To make it work inside a Docker container, you have to set up a sort of digital tunnel, so your computer can talk to the gadget. Itâs like creating a secret pathway. In tech terms, you might need to use specific commands or configurations to tell the Docker container how to reach out and grab information from the external hardware. Think of it as helping your computer and the gadget have a smooth conversation, even though theyâre in different places. Just like giving your computer the right map to find and use the cool tool outside.
This really helped a lot Thanks for giving the clear idea can you suggest any way like that so that I can communicate with the external hardware any suggestions
Thanks for the reply will try to implement this method But I donât think it might work
Is it possible to pass through usb from linux host to linux container is that possible ?
USBIP (USB over IP) will definitely work, you can specify the host server (where the USB devices reside) only any machine (Windows, Linux, Mac, etc), which includes the Windows Host of a WSL2 setup.
You then use a usbip client on the target device to bind/import the remote USB resource, will appear as a local USB device. USBIP exchanges URB (USB Request Blocks) between the server/client, which are then âpassed up/downâ the USB driver stack as if the device was local.
So the steps are:
From the âserverâ, publish (bind) the USB devices
From the WSL2 distro, attach to the published devices (specifying host/port if not default)
From the docker container, map the devices per the names in the WSL2 distro attach above.
The one problem is if the USB device is unplugged you need to re-attach via the WSL2 distro and you wonât be guaranteed the device name will be the same (in most cases it wonât). There are ways of using the cgroups to ensure consistent name mapping, or take a look at the python package serial-usbipclient for how to directly connect any Python instance to a USB serial device hosted by a USBIP server.
Thank you for the input. It is known to work with WSL2 distros, though did you manage to make it work with Docker Desktop for Windows, where the distro is more like an appliance? If so, can you share the exact steps necessary to make containers in Docker Desktop for Windows use usb devices?
No, I was using a docker-desktop-less implementation.
My last project was a scientific instrument, we chose to host the docker containers on a Windows (10) computer with docker services running on the host (Windows) and the WSL2 distro. We could use the ânormalâ docker commands and docker-compose to run our containers (both Windows and Linux containers).
The h/w was connected to the host (Windows) and using usbipd-win âpublishedâ (shared). An initialization script in the WSL2 distro would attach the published USB ports (3 in total) and assign them to local devices (e.g. /dev/ttyACM0, /dev/ttyACM1, /dev/ttyACM2). When the docker container was launched, it would specify the mapping of the WSL2 distro device to the container.
Problem with this approach is if the devices are unplugged they will re-appear with different device names (e.g. /dev/ttyACM3). Since the binding of the device happens when the docker container is launched, thereâs no way to re-map the device.
There are two solutions. One is to re-map the device using scripts that fiddle with the cgroup, the other is to directly attach to the usbipd server (itâs just tcp/ip) and use a network connection within the container. This is what the package serial-usbipclient does, eliminating all the device mapping, you just have to âpublishâ the devices from the host.
Docker Desktop runs on top of docker, but is limited as running containers from different platforms (Windows & Linux) isnât well supported. But, if you are just running linux containers you can do all that I previously mentioned.