最近爆火的项目,支持在 docker 下运行 windows 了,尝尝鲜:
https://github.com/dockur/windows
在服务器上尝试运行报错:
$ docker run -it --name windows
-p 8006:8006
--device=/dev/kvm
--cap-add NET_ADMIN
--stop-timeout 120
dockurr/windows
❯ Starting Windows for Docker v2.06...
❯ For support visit https://github.com/dockur/windows
qemu: qemu_thread_create: Operation not permitted
❯ ERROR: Status 134 while: cut -d '(' -f 1 (line 46/10)
❯ ERROR: Status 134 while: VERS=$(qemu-system-x86_64 --version | head -n 1 | cut -d '(' -f 1) (line 46/10)
服务器操作系统版本太老,系统版本是 Ubuntu 16.04.5 LTS。于是换我的笔记本尝试,笔记本的系统是 Ubuntu 23.10 x64,各种软件包比较新。
相同的命令执行后,开始下载 win11 镜像:
目前项目支持的 windows 系统有:
默认使用的系统镜像是 win11,也可以通过环境变量来控制所安装的系统。本来就是尝鲜,一切使用默认配置,从微软官网下载镜像的速度大概为 1.5MB/s 左右,提示需要40分钟左右,win11 镜像大小为 6.4 GB,docker image 大小为 432 MB:
docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
latest b8bbd430df05 8 hours ago 432MB
系统下载完了后,访问 web 页面 http://<ip>:8006
刚开始提示正在解压 win11,解压完提示启动失败,系统关闭。
详细日志如下:
❯ Starting Windows for Docker v2.06...
❯ For support visit https://github.com/dockur/windows
❯ Downloading Windows 11...
[i] Downloading Windows media from official Microsoft servers...
[i] Downloading Windows 11...
curl: (7) Failed to connect to vlscppe.microsoft.com port 443 after 262 ms: Couldn't connect to server
[!] Failed to contact Microsoft servers! Is there an Internet connection or is the server down?
[!] 1 attempted download(s) failed! Please re-run Mido with these arguments to try downloading again (any partial downloads will be resumed): win11x64
[+] Finished! Please see the above errors with information
❯ Failed to download Windows 11 using Mido, will try a different method now...
❯ Downloading product information from Microsoft...
❯ Downloading Windows 11...
/storage/tmp/win11x64.esd 100%[=======================================================>] 4.54G 1.81MB/s in 45m 29s
❯ Extracting Windows 11 bootdisk...
❯ Extracting Windows 11 environment...
❯ Extracting Windows 11 setup...
❯ Extracting Windows 11 image...
❯ Adding XML file for automatic installation...
❯ Building Windows 11 image...
❯ Creating a 64G growable disk image in raw format...
❯ Booting Windows using QEMU emulator version 8.2.1 ...
BdsDxe: failed to load Boot0002 "UEFI QEMU QEMU HARDDISK " from PciRoot(0x0)/Pci(0xA,0x0)/Scsi(0x0,0x0): Not Found
BdsDxe: loading Boot0001 "UEFI QEMU QEMU CD-ROM " from PciRoot(0x0)/Pci(0x5,0x0)/Scsi(0x0,0x0)
BdsDxe: starting Boot0001 "UEFI QEMU QEMU CD-ROM " from PciRoot(0x0)/Pci(0x5,0x0)/Scsi(0x0,0x0)
❯ Shutdown completed!
重启容器,再次访问 http://<ip>:8006,开始安装 windows:
很快装完系统,系统进入初始化阶段:
使用 docker logs 观察容器日志:
❯ Booting Windows using QEMU emulator version 8.2.1 ...
BdsDxe: failed to load Boot0002 "UEFI QEMU QEMU HARDDISK " from PciRoot(0x0)/Pci(0xA,0x0)/Scsi(0x0,0x0): Not Found
BdsDxe: loading Boot0001 "UEFI QEMU QEMU CD-ROM " from PciRoot(0x0)/Pci(0x5,0x0)/Scsi(0x0,0x0)
BdsDxe: starting Boot0001 "UEFI QEMU QEMU CD-ROM " from PciRoot(0x0)/Pci(0x5,0x0)/Scsi(0x0,0x0)
BdsDxe: loading Boot0003 "Windows Boot Manager" from HD(1,GPT,AC1B4ADF-F73C-42B1-8FAA-7803D78FCEB9,0x800,0x40000)/EFIMicrosoftBootbootmgfw.efi
BdsDxe: starting Boot0003 "Windows Boot Manager" from HD(1,GPT,AC1B4ADF-F73C-42B1-8FAA-7803D78FCEB9,0x800,0x40000)/EFIMicrosoftBootbootmgfw.efi
后续可以看到 windows 系统初始化的过程:
最终效果如下:
系统是未激活的,使用的是原版系统,创建了一个叫 docker 的本地账户。
docker 内的 win11 系统也是可以访问网络的,与宿主机网络权限相同。尝试使用远程桌面但发现 docker 创建容器时没有映射 3389 端口,后续改密码、映射端口等功能还在尝试。
全文完。
如果转发本文,文末务必注明:“转自微信公众号:生有可恋”。
原文始发于微信公众号(生有可恋):docker 下运行 windows