Windows 10 reading usb data from windows docker container - windows

I have a program that reads some data from USB, I would be running it as docker container (windows 10) on windows 10, I would like to know if it is possible to read the usb data when I run the program as container (windows container) where base operating system is windows 10.
Regards,
Amit

If a key goal of the process is to access hardware devices, it’s best to not run in a Docker container, which intentionally tries to hide details of the underlying hardware from you. That’s doubly true if you need to use Docker Toolbox, which adds an additional layer of virtual machine.
In addition to USB devices, I’d also avoid Docker if your goals include installing software on the host, reconfiguring or monitoring the host’s network interfaces, or accessing other hardware devices like sound or display configuration.

Related

Docker Container vs Virtual Machine

I am using docker desktop on windows 10. I downloaded an image for windows server core 1909.
then created two containers from the same image.
Docker run -it mcr.microsoft.com/windows/servercore:1909 powershell.exe
when I ran sysinfo on both, it gave me different hostname for both OS.
how do I see that kernel is shared? because I see these are two different VMs which is no different than hyper-v VM of the core OS.
I though docker container is sharing a kernel but I don't see the same OS underneath?
any idea?
Ok i got the answer also. There is concept of hyper-v isolation level for containers in windows. so if the host is not same version as of the container, you will get what you call hyper-v isolation which is essentially not a process isolation, its rather a virtual machine like traditional thing. no shared kernel.
True container concept which is actually shared kernel is only possible on windows server host and when used container version which is also same.
https://learn.microsoft.com/en-us/virtualization/windowscontainers/deploy-containers/version-compatibility?tabs=windows-server-1909%2Cwindows-10-1809

Docker on Windows 10 Home

My question is: If you use Docker tool box (that is required for windows 10 home to run Docker) you are essentially using a virtual machine (vm)?
If you are using a vm already the only reason to use docker from that point is to save on many more multiple instances?
Meaning if you only want 1 extra (guest instance): you can have a vm. Though, with docker (toolbox on windows 10 home) you would have 1 vm and it runs docker?
The only way that is useful is if you want many more instances as in: 1 vm + 1 docker or + 1000 more dockers?
Or am I missing something?
Yes, docker toolbox uses Oracle VirtualBox cause Windows 7, 8, and Windows 10 home cannot use Hyper V. And yes, If you are using a VM already the only reason to use docker from that point is to save on many more multiple instances but it also allows easy backup and deployment. But you are losing a decent amount of memory when running a VM and then even more when you are running docker.
So although Docker CE will tell you your Windows doesn't support Hyper-V, this isn't always the case (if you check in System Info you might have Hyper-V enabled, if you're on an Insider build or many builds on GPU computers after Anniversary update then you probably have Hyper-V on Windows 10 Home). There are a few workarounds until the Docker team addresses this issue.
You could use Docker from inside WSL (Windows Subsystem for Linux). Microsoft claims WSL accesses everything directly without Hyper-V so this should be theoretically at the same speed. Of course you can't use your GPU at all because of limitations with GPU passthrough on WSL, which you can ask to be resolved here.
You can also use Docker Toolbox as the other answer stated with Virtualbox, but this will be inherently much slower as you're virtualizing a container inside a virtualized container. You should be able to theoretically get GPU support through this, as well as other features e.g. GUI that you wouldn't be able to with WSL.
To answer the "usefulness" portion of the question:
It's also useful if you run code on a server, but need to develop/debug/update it. You want to test it locally, but to make sure the environment in which it executes is the same (to avoid unexpected, environment specific behavior), you use Docker both locally and on the server. In such a case, even though it's slow, I'll spin up a VM on my W10 Home laptop and run Docker in it.
The greatest feature of the Windows 10 Home May 2020 Update is Windows Subsystem for Linus 2. You can docker in it without the need for a complete virtual machine as in Virtual Box.
Install Docker Desktop that it will automatically indentify WSL2.

Pass USB device into a Docker Windows Container

I'm on Windows 10 using Docker for Windows. Also, I have a container which originates FROM microsoft/windowsservercore. I have an USB device attached and want to pass it to that container.
What I found so far:
Under Linux you got --device=/dev/.., but how can I accomplish this under Windows?
Michael Friis wrote on 2017-07-07 that this is currently not possible. However, this comment states that it is.
So my questions are:
Is it currently possible to pass an USB device from a Windows Host into a Windows Docker container?
If yes, what is the correct syntax?
If not, when approximately can we expect this feature?
You cannot directly pass USB to the container. Either you have to run Docker as a VM or use USB/IP (where the USB data is transferred as IP packets). But there will be a delay in the second method.
I spent a day trying to figure out this problem, unfortunately there is no way to passthru USB devices to Windows containers as for now (Sep 2022).
Hyper-V doesn't support USB Passthru per se. While USB-IP seems like a viable solution, it requires installing custom drivers (usually self-signed), which is not support with Windows containers.
USB passthrough is currently not supported with Windows for Docker as of November 2017:
Docker for Windows USB Support
There is a way to pass USB through to Docker for Desktop running on windows. If the docker engine is running using WSL2 (Settings -> General -> Use the WSL 2 based engine) then you can attach a usb device using the usbipd libraries.
Details on USBIPD library and download:
https://learn.microsoft.com/en-us/windows/wsl/connect-usb
I went into Command Prompt and typed in:
usbipd wsl list
Found the USB device that I wanted available in my docker container and then attached it in usbipd using the command:
usbipd wsl attach --busid <bus-id>
In the docker compose script I have:
devices:
- /dev/ttyUSB0:/dev/ttyUSB0
Which is where the usb device is being seen when I go into the container and go to /dev I see that ttyUSB0 is listed.
I can now use that USB device.. the trick is that the device needs to be attached using the usbipd command before the container starts or you will need to restart the containers for the container OS to see everything.
If you have that devices statement in your compose you might fine to attach and detach using usbipd and it just works since it would take the ttyUSB0 each time.

docker - does it bypass instance-checking limitation like virtual machine

QUESTION
For instance-checking, does docker provide same level of abstraction as a virtual machine?
BACKGROUND
I have some software that is license-limited to one instance per machine. I know that if I install N virtual machines, I can have N instances of this software running on the same machine.
Is the same true of docker? Does it trick this tool's instance-checking mechanism?
Docker is a container. It holds all resources required to run an application that can be installed. My understanding is that this extends to all of Userspace, but does not encroach on Kernelspace. Therefore any Linux kernel which supports the included software in a Docker image can run that docker image. The kernel itself is shared between applications, and does not virtualize kernel operations for each docker image (One kernel, many containers).
A VM host may spin up a/many VM(s) that can host a/many Docker image(s), while the host (With the proper supporting packages) may also natively run a/many docker image(s) without a VM running.

Is it possible to access a hardware device with a Docker image under Windows?

Recently, a native Docker client for Windows was released (>= Windows 7).
I wonder: is it possible to forward access to physical devices, running Windows as host?
With a *nix host, this seems to be possible with the following syntax:
docker run -t -i --device=/dev/ttyUSB0 ubuntu bash
(as proposed here) which would forward the USB device /dev/ttyUSB0 on a *nix system to the docker image.
A description of the --device flag can be found in the docker docs.
What would be the syntax for a Windows host?
Windows USB devices are not currently available to Docker containers run with Docker for Windows.
Answered by a Docker staff member on the 7th of July 2017 in the Docker forum.
https://forums.docker.com/t/exposing-docker-to-usb-device-in-windows-10-with-docker-toolbox/29290/3
This answer is likely to get outdated in some time, provided they will allow for this feature somehow.
This is a bad practice as it goes against the design philosophy of containers.
If you find yourself needing access to a hardware device, it's better to consider full virtualization such as VMware, Hyper-V, KVM/QEMU, Xen and so on.
However, the "proper" way is to design your system
so that hardware is abstracted into a network service. In this way, you deploy the service to physical machines to which the hardware is attached, and call them over the network. I don't know if this is possible in your case, but such decoupling provides a significant architectural advantage.

Resources