如何将KVM从本地机器传递到docker容器?

Sta*_*y T 1 continuous-integration android docker

我正在尝试通过下一个命令在 Docker 容器中启动 Android 模拟器(又名 AVD)

docker run -it img_emulator:v1 
Run Code Online (Sandbox Code Playgroud)

但我收到以下错误:

emulator: CPU Acceleration: DISABLED
emulator: CPU Acceleration status: /dev/kvm is not found: VT disabled in BIOS or KVM kernel module not loaded
emulator: ERROR: x86_64 emulation currently requires hardware acceleration!
Please ensure KVM is properly installed and usable.
CPU acceleration status: /dev/kvm is not found: VT disabled in BIOS or KVM kernel module not loaded
Run Code Online (Sandbox Code Playgroud)

事实上,我的笔记本电脑上有 Linux 18.04 虚拟化。我在 Bios 中启用了它并通过下一个命令检查它:

kvm-ok
Run Code Online (Sandbox Code Playgroud)

系统报告:

INFO: /dev/kvm exists
KVM acceleration can be used
Run Code Online (Sandbox Code Playgroud)

可能我必须使用类似这样的命令来运行我的图像并传递到 KVM:

docker run -it img_emulator:v1 --device /dev/kvm
Run Code Online (Sandbox Code Playgroud)

但这不起作用。有人可以帮我解决这个问题吗?

atl*_*ine 6

kvm is a kernel module, so it could be shared by container. Looks you put --device /dev/kvm at a wrong command place, the correct is:

docker run -idt --device /dev/kvm --name trial ubuntu:18.04
Run Code Online (Sandbox Code Playgroud)

Then, copy the kvm-ok script from host to container:

docker cp /usr/sbin/kvm-ok trial:/opt
Run Code Online (Sandbox Code Playgroud)

Finally, verify kvm in container:

$ docker exec -it trial /opt/kvm-ok
INFO: /dev/kvm exists
KVM acceleration can be used
Run Code Online (Sandbox Code Playgroud)