How to use a host USB device in a container in Docker Desktop?

Kindly take a note of each and every point I will be sending

  1. 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

  2. these two images are in two containers but they are in same network

  3. My host system is windows machine

  4. 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

  5. Docker file for mysql application
    FROM mysql:latest
    ENV MYSQL_ROOT_PASSWORD=‘PASSWORD’
    COPY mysqlinit.sql /docker-entrypoint-initdb.d/
    EXPOSE 3306

  6. docker-compose.yml file
    version: “1.0”
    services:
    projcont:
    build:
    context: .
    dockerfile: Dockerfile
    ports:

    • 27997:27997
    • 5005:5005
    • “127.0.0.1:4500:4500”

    depends_on:

    • evmysqlcont

    devices:

    - “/dev/bus/usb:/dev/bus/usb” # Mount the entire USB bus

    devices:

    - “//./USB/VID_1248&PID_1001/5&271999B4&0&1”

    cap_add:

    - SYS_ADMIN

evmysqlcont:
build:
context: mysqlContainer
dockerfile: Dockerfile
ports:
- 27999:3306

Can anyone help how external hardware connected to windows can be detected in debian docker container ?

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.

1 Like

According official Docker Desktop FAQs, it is not possible to pass through a USB device:

Though, you could try if you get https://github.com/dorssel/usbipd-win working somehow.

1 Like

Hello,

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.

I hope this will help you.

Regards

1 Like

Yes I use docker desktop


Yes I need to attach the usb to VM too
or can you recommend any tool like VM Box where i can use docker and usb both

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 ?

Of course, as long as you run docker-ce, and not Desktop Desktop.

Can you send the way how to use that ?

Apologies, my wording was kind of ambiguous with run I mean install and run dock-ce.

You can find the official installation instructions here: