[英]How can I access my device from a windows host to a docker linux container?
I have a desktop with Windows 10 and an elgato capture card.我有一个带有 Windows 10 和一个 elgato 采集卡的桌面。 I am using OpenCV to capture the frames of the video for processing.我正在使用 OpenCV 来捕获视频帧进行处理。 So far, everything works perfectly fine:到目前为止,一切正常:
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
# Our operations on the frame come here
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Display the resulting frame
cv2.imshow('frame', gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
The next step I want to do is utilize the Remote Development Extensions .我想做的下一步是利用Remote Development Extensions 。 This extension, with VS Code, works perfectly fine for my other python projects.这个带有 VS Code 的扩展非常适合我的其他 python 项目。 This is the first project I am writing that utilizes a hardware device, but my linux container cannot access the hardware that the host has access to.这是我编写的第一个使用硬件设备的项目,但是我的 linux 容器无法访问主机可以访问的硬件。 I attempted to search for a solution, but all I have found is a way for using the --device
parameter in my docker
command with the examples pointing from a *nix device path to another *nix device path.我试图寻找解决方案,但我发现的只是一种在我的docker
命令中使用--device
参数的方法,示例从 *nix 设备路径指向另一个 *nix 设备路径。
I did come across a post from the docker desktop team that is over two (2) years old saying that you cannot access hardware from a windows host to a linux container.我确实遇到过两 (2) 岁以上的 docker 桌面团队的帖子,说您无法从 windows 主机访问硬件到 linux 容器。 I'm not sure if that is still the case, and I'm not sure if the remote containers extension has a way to access the devices... there is some magic that goes on in that the extension installs a vscode-server on the container, so I'm not sure if that would allow hardware access?我不确定情况是否仍然如此,并且我不确定远程容器扩展是否有办法访问设备......有一些神奇之处在于扩展安装了一个 vscode-server容器,所以我不确定这是否允许硬件访问?
According to Microsoft's Official documentation , you can't share a device from a Windows Host to a Linux container.根据 Microsoft 的官方文档,您不能将设备从 Windows 主机共享到 Linux 容器。 You can however share a device to a Windows container, but I guess this isn't what you want.但是,您可以将设备共享到 Windows 容器,但我想这不是您想要的。
You can however use docker-machine to share your devices, this is because docker-machine uses a Virtual Machine such a VirtualBox instead of their custom engine to run the container's processes.但是,您可以使用docker-machine来共享您的设备,这是因为 docker-machine 使用诸如 VirtualBox 之类的虚拟机而不是其自定义引擎来运行容器的进程。
Once you have docker-machine installed you can simply execute the command安装 docker-machine 后,您可以简单地执行命令
docker-machine create --driver virtualbox <A name for the machine>
Then you open VirtualBox which should be in your programs and add the device manually.然后你打开应该在你的程序中的 VirtualBox 并手动添加设备。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.