qemu-docker

qemu-docker

基于QEMU的Docker虚拟机解决方案

qemu-docker是基于QEMU的Docker容器,用于运行虚拟机。它提供Web查看器,支持多种磁盘格式,具备KVM加速和内核模式网络等高性能特性。用户可通过简单配置启动各种操作系统,自定义存储位置、磁盘大小、CPU和RAM等资源。该项目适合在容器环境中快速部署和管理虚拟机的开发者及系统管理员使用。

QEMU虚拟机Docker容器系统镜像虚拟化Github开源项目
<h1 align="center">QEMU<br /> <div align="center"><a href="https://github.com/qemus/qemu-docker"><img src="https://github.com/qemus/qemu-docker/raw/master/.github/logo.png" title="Logo" style="max-width:100%;" width="128" /></a> </div> <div align="center">

Build Version Size Package Pulls

</div></h1>

Docker container for running virtual machines using QEMU.

Features ✨

  • Web-based viewer to control the machine directly from your browser

  • Supports .iso, .img, .qcow2, .vhd, .vhdx, .vdi, .vmdk and .raw disk formats

  • High-performance options (like KVM acceleration, kernel-mode networking, IO threading, etc.) to achieve near-native speed

Usage 🐳

Via Docker Compose:

services: qemu: container_name: qemu image: qemux/qemu-docker environment: BOOT: "https://dl-cdn.alpinelinux.org/alpine/v3.19/releases/x86_64/alpine-virt-3.19.1-x86_64.iso" devices: - /dev/kvm cap_add: - NET_ADMIN ports: - 8006:8006 stop_grace_period: 2m

Via Docker CLI:

docker run -it --rm -e "BOOT=http://example.com/image.iso" -p 8006:8006 --device=/dev/kvm --cap-add NET_ADMIN qemux/qemu-docker

Via Kubernetes:

kubectl apply -f kubernetes.yml

FAQ 💬

How do I use it?

Very simple! These are the steps:

  • Set the BOOT environment variable to the URL of any disk image you want to install.

  • Start the container and connect to port 8006 using your web browser.

  • You will see the screen and can now install the OS of your choice using your keyboard and mouse.

Enjoy your brand new machine, and don't forget to star this repo!

How do I change the storage location?

To change the storage location, include the following bind mount in your compose file:

volumes: - /var/qemu:/storage

Replace the example path /var/qemu with the desired storage folder.

How do I change the size of the disk?

To expand the default size of 16 GB, add the DISK_SIZE setting to your compose file and set it to your preferred capacity:

environment: DISK_SIZE: "128G"

[!TIP] This can also be used to resize the existing disk to a larger capacity without any data loss.

How do I boot a local image?

You can use a local image file directly, and skip the download altogether, by binding it in your compose file:

volumes: - /home/user/example.iso:/boot.iso

This way you can supply a boot.iso, boot.img or boot.qcow2 file.

[!NOTE] The URL of the BOOT variable will be ignored in this case.

How do I boot ARM images?

You can use qemu-arm to run ARM64-based images.

How do I boot Windows?

Use dockur/windows instead, as it includes all the drivers required during installation, amongst many other features.

How do I boot macOS?

Use dockur/macos instead, as it uses all the right settings and automaticly downloads the installation files.

How do I boot without VirtIO drivers?

By default, the machine makes use of virtio-scsi drives for performance reasons, and even though most Linux kernels bundle the necessary driver for this device, that may not always be the case for other operating systems.

If your machine fails to detect the hard drive, you can modify your compose file to use virtio-blk instead:

environment: DISK_TYPE: "blk"

[!TIP] If it still fails to boot, you can set the value to ide to emulate a IDE drive, which is slow but requires no drivers and is compatible with almost every system.

How do I change the amount of CPU or RAM?

By default, the container will be allowed to use a maximum of 1 CPU core and 1 GB of RAM.

If you want to adjust this, you can specify the desired amount using the following environment variables:

environment: RAM_SIZE: "4G" CPU_CORES: "4"

How do I verify if my system supports KVM?

To verify that your system supports KVM, run the following commands:

sudo apt install cpu-checker sudo kvm-ok

If you receive an error from kvm-ok indicating that KVM acceleration can't be used, please check whether:

  • the virtualization extensions (Intel VT-x or AMD SVM) are enabled in your BIOS.

  • you are running an operating system that supports them, like Linux or Windows 11 (macOS and Windows 10 do not unfortunately).

  • you enabled "nested virtualization" if you are running the container inside a virtual machine.

  • you are not using a cloud provider, as most of them do not allow nested virtualization for their VPS's.

If you didn't receive any error from kvm-ok at all, but the container still complains that /dev/kvm is missing, it might help to add privileged: true to your compose file (or --privileged to your run command), to rule out any permission issue.

How do I assign an individual IP address to the container?

By default, the container uses bridge networking, which shares the IP address with the host.

If you want to assign an individual IP address to the container, you can create a macvlan network as follows:

docker network create -d macvlan \ --subnet=192.168.0.0/24 \ --gateway=192.168.0.1 \ --ip-range=192.168.0.100/28 \ -o parent=eth0 vlan

Be sure to modify these values to match your local subnet.

Once you have created the network, change your compose file to look as follows:

services: qemu: container_name: qemu ..<snip>.. networks: vlan: ipv4_address: 192.168.0.100 networks: vlan: external: true

An added benefit of this approach is that you won't have to perform any port mapping anymore, since all ports will be exposed by default.

[!IMPORTANT] This IP address won't be accessible from the Docker host due to the design of macvlan, which doesn't permit communication between the two. If this is a concern, you need to create a second macvlan as a workaround.

How can the VM acquire an IP address from my router?

After configuring the container for macvlan, it is possible for the VM to become part of your home network by requesting an IP from your router, just like a real PC.

To enable this mode, add the following lines to your compose file:

environment: DHCP: "Y" devices: - /dev/vhost-net device_cgroup_rules: - 'c *:* rwm'

[!NOTE] In this mode, the container and the VM will each have their own separate IPs.

How do I add multiple disks?

To create additional disks, modify your compose file like this:

environment: DISK2_SIZE: "32G" DISK3_SIZE: "64G" volumes: - /home/example:/storage2 - /mnt/data/example:/storage3

How do I pass-through a disk?

It is possible to pass-through disk devices directly by adding them to your compose file in this way:

devices: - /dev/sdb:/disk1 - /dev/sdc:/disk2

Use /disk1 if you want it to become your main drive, and use /disk2 and higher to add them as secondary drives.

How do I pass-through a USB device?

To pass-through a USB device, first lookup its vendor and product id via the lsusb command, then add them to your compose file like this:

environment: ARGUMENTS: "-device usb-host,vendorid=0x1234,productid=0x1234" devices: - /dev/bus/usb

How can I provide custom arguments to QEMU?

You can create the ARGUMENTS environment variable to provide additional arguments to QEMU at runtime:

environment: ARGUMENTS: "-device usb-tablet"

What image formats are supported?

The BOOT URL accepts files in any of the following formats:

ExtensionFormat
.imgRaw
.rawRaw
.isoOptical
.qcow2QEMU
.vmdkVMware
.vhdVirtualPC
.vhdxHyper-V
.vdiVirtualBox

[!TIP] It will also accept .img.gz, .qcow2.xz, .iso.zip and many more, as it automaticly extracts compressed files.

Stars 🌟

Stars

编辑推荐精选

酷表ChatExcel

酷表ChatExcel

大模型驱动的Excel数据处理工具

基于大模型交互的表格处理系统,允许用户通过对话方式完成数据整理和可视化分析。系统采用机器学习算法解析用户指令,自动执行排序、公式计算和数据透视等操作,支持多种文件格式导入导出。数据处理响应速度保持在0.8秒以内,支持超过100万行数据的即时分析。

AI工具酷表ChatExcelAI智能客服AI营销产品使用教程
DeepEP

DeepEP

DeepSeek开源的专家并行通信优化框架

DeepEP是一个专为大规模分布式计算设计的通信库,重点解决专家并行模式中的通信瓶颈问题。其核心架构采用分层拓扑感知技术,能够自动识别节点间物理连接关系,优化数据传输路径。通过实现动态路由选择与负载均衡机制,系统在千卡级计算集群中维持稳定的低延迟特性,同时兼容主流深度学习框架的通信接口。

DeepSeek

DeepSeek

全球领先开源大模型,高效智能助手

DeepSeek是一家幻方量化创办的专注于通用人工智能的中国科技公司,主攻大模型研发与应用。DeepSeek-R1是开源的推理模型,擅长处理复杂任务且可免费商用。

问小白

问小白

DeepSeek R1 满血模型上线

问小白是一个基于 DeepSeek R1 模型的智能对话平台,专为用户提供高效、贴心的对话体验。实时在线,支持深度思考和联网搜索。免费不限次数,帮用户写作、创作、分析和规划,各种任务随时完成!

AI主流办公工具有哪些办公热门AI 助手
KnowS

KnowS

AI医学搜索引擎 整合4000万+实时更新的全球医学文献

医学领域专用搜索引擎整合4000万+实时更新的全球医学文献,通过自主研发AI模型实现精准知识检索。系统每日更新指南、中英文文献及会议资料,搜索准确率较传统工具提升80%,同时将大模型幻觉率控制在8%以下。支持临床建议生成、文献深度解析、学术报告制作等全流程科研辅助,典型用户反馈显示每周可节省医疗工作者70%时间。

Windsurf Wave 3

Windsurf Wave 3

Windsurf Editor推出第三次重大更新Wave 3

新增模型上下文协议支持与智能编辑功能。本次更新包含五项核心改进:支持接入MCP协议扩展工具生态,Tab键智能跳转提升编码效率,Turbo模式实现自动化终端操作,图片拖拽功能优化多模态交互,以及面向付费用户的个性化图标定制。系统同步集成DeepSeek、Gemini等新模型,并通过信用点数机制实现差异化的资源调配。

AI IDE
腾讯元宝

腾讯元宝

腾讯自研的混元大模型AI助手

腾讯元宝是腾讯基于自研的混元大模型推出的一款多功能AI应用,旨在通过人工智能技术提升用户在写作、绘画、翻译、编程、搜索、阅读总结等多个领域的工作与生活效率。

AI助手AI对话AI工具腾讯元宝智能体热门 AI 办公助手
Grok3

Grok3

埃隆·马斯克旗下的人工智能公司 xAI 推出的第三代大规模语言模型

Grok3 是由埃隆·马斯克旗下的人工智能公司 xAI 推出的第三代大规模语言模型,常被马斯克称为“地球上最聪明的 AI”。它不仅是在前代产品 Grok 1 和 Grok 2 基础上的一次飞跃,还在多个关键技术上实现了创新突破。

OmniParser

OmniParser

帮助AI理解电脑屏幕 纯视觉GUI元素的自动化解析方案

开源工具通过计算机视觉技术实现图形界面元素的智能识别与结构化处理,支持自动化测试脚本生成和辅助功能开发。项目采用模块化设计,提供API接口与多种输出格式,适用于跨平台应用场景。核心算法优化了元素定位精度,在动态界面和复杂布局场景下保持稳定解析能力。

OmniParser界面解析交互区域检测Github开源项目
流畅阅读

流畅阅读

AI网页翻译插件 双语阅读工具,还原母语级体验

流畅阅读是一款浏览器翻译插件,通过上下文智能分析提升翻译准确性,支持中英双语对照显示。集成多翻译引擎接口,允许用户自定义翻译规则和快捷键配置,操作数据全部存储在本地设备保障隐私安全。兼容Chrome、Edge、Firefox等主流浏览器,基于GPL-3.0开源协议开发,提供持续的功能迭代和社区支持。

AI翻译AI翻译引擎AI翻译工具
下拉加载更多