在Docker中安装Windows系统,远程控制
经常挂一些辅助软件,基本都是Windows的,然而电脑功耗太大,一天开不起,但有一个Ubuntu 服务器,心想能不能在服务器上安装Windows来挂载呢?经过研究找到方法,其实早已有了,是GITHUB上的开源项目,利用万能的Docker来安装Windows
项目中已有安装方法,但是是英文的,勉强可读。
通过Docker compose 来安装
services:
windows:
image: dockurr/windows
container_name: winxp
environment:
#VERSION: "xp"
DISK_SIZE: "32G"
RAM_SIZE: "2G"
USERNAME: "admin"
PASSWORD: "1"
LANGUAGE: "cn"
VERSION: "https://qqai.ren:8443/xunlei/en_win_xp_pro_x64_with_sp2_vl_x13-41611.iso"
devices:
- /dev/kvm
cap_add:
- NET_ADMIN
ports:
- 28006:8006
- 23389:3389/tcp
- 23389:3389/udp
stop_grace_period: 2m
命令安装
sudo docker run -it --rm -p 8006:8006 --device=/dev/kvm --cap-add NET_ADMIN --stop-timeout 120 dockurr/windows
如何使用它?
非常简单!以下是步骤:
启动容器,并使用您的网络浏览器连接到8006端口。
坐下来放松,让奇迹发生,整个安装过程将全自动完成。
一旦您看到桌面,您的Windows安装就准备好使用了。
享受您的全新机器,别忘了给这个仓库点赞!
我如何选择Windows版本?
默认情况下,将安装Windows 11专业版。但您可以在compose文件中添加VERSION环境变量,以指定要下载的替代Windows版本:
environment:
VERSION: "11"
从以下值中选择:
**Value 价值 | Version 版本 | Size 大小 |
---|---|---|
11 |
Windows 11 Pro Windows 11 专业版 | 5.4 GB 5.4 吉字节 |
11l |
Windows 11 LTSC | 4.2 GB 4.2 吉字节 |
11e |
Windows 11 Enterprise Windows 11 企业版 | 5.8 GB 5.8 吉字节 |
10 |
Windows 10 Pro Windows 10 专业版 | 5.7 GB 5.7 吉字节 |
10l |
Windows 10 LTSC | 4.6 GB 4.6 吉字节 |
10e |
Windows 10 Enterprise Windows 10 企业版 | 5.2 GB 5.2 吉字节 |
8e |
Windows 8.1 Enterprise Windows 8.1 企业版 | 3.7 GB 3.7 吉字节 |
7e |
Windows 7 Enterprise Windows 7 企业版 | 3.0 GB 3.0 吉字节 |
ve |
Windows Vista Enterprise Windows Vista 企业版 | 3.0 GB 3.0 吉字节 |
xp |
Windows XP Professional Windows XP 专业版 | 0.6 GB 0.6 吉字节 |
2025 |
Windows Server 2025 Windows 服务器 2025 | 5.0 GB 5.0 吉字节 |
2022 |
Windows Server 2022 Windows 服务器 2022 | 4.7 GB 4.7 吉字节 |
2019 |
Windows Server 2019 Windows 服务器 2019 | 5.3 GB 5.3 吉字节 |
2016 |
Windows Server 2016 Windows 服务器 2016 | 6.5 GB 6.5 吉字节 |
2012 |
Windows Server 2012 Windows 服务器 2012 | 4.3 GB 4.3 吉字节 |
2008 |
Windows Server 2008 Windows 服务器 2008 | 3.0 GB 3.0 吉字节 |
2003 |
Windows Server 2003 Windows 服务器 2003 | 0.6 GB 0.6 吉字节 |
如何更改存储位置?
To change the storage location, include the following bind mount in your compose file:
要更改存储位置,请在 compose 文件中包含以下绑定挂载:
volumes:
- /var/win:/storage
Replace the example path /var/win
with the desired storage folder.
将示例路径 /var/win
替换为所需的存储文件夹。
How do I change the size of the disk? 如何更改磁盘的大小?
To expand the default size of 64 GB, add the DISK_SIZE
setting to your compose file and set it to your preferred capacity:
要扩展默认大小 64 GB,请将 DISK_SIZE
设置添加到编写文件并将其设置为首选容量:
environment:
DISK_SIZE: "256G"
Tip 提示
This can also be used to resize the existing disk to a larger capacity without any data loss.
这还可用于将现有磁盘的大小调整为更大的容量,而不会丢失任何数据。
How do I share files with the host? 如何与主机共享文件?
Open ‘File Explorer’ and click on the ‘Network’ section, you will see a computer called host.lan
. Double-click it and it will show a folder called Data
, which can be bound to any folder on your host via the compose file:
打开“文件资源管理器”并单击“网络”部分,您将看到一台名为 host.lan
的计算机。双击它,它将显示一个名为 Data
的文件夹,该文件夹可以通过 compose 文件绑定到主机上的任何文件夹:
volumes:
- /home/user/example:/data
The example folder /home/user/example
will be available as \\host.lan\Data
.
示例文件夹 /home/user/example
将作为 \\host.lan\Data
提供。
Tip 提示
You can map this path to a drive letter in Windows, for easier access.
您可以将此路径映射到 Windows 中的驱动器号,以便于访问。
How do I install a custom image? 如何安装自定义镜像?
In order to download an unsupported ISO image that is not selectable from the list above, specify the URL of that ISO in the VERSION
environment variable, for example:
要下载无法从上述列表中选择的不受支持的 ISO 映像,请在 VERSION
环境变量中指定该 ISO 的 URL,例如:
environment:
VERSION: "https://example.com/win.iso"
Alternatively, you can also skip the download and use a local file instead, by binding it in your compose file in this way:
或者,您也可以跳过下载并使用本地文件,方法是通过以下方式将其绑定到 compose 文件中:
volumes:
- /home/user/example.iso:/custom.iso
Replace the example path /home/user/example.iso
with the filename of your desired ISO file, the value of VERSION
will be ignored in this case.
将示例路径 /home/user/example.iso
替换为所需 ISO 文件的文件名,在这种情况下,VERSION
的值将被忽略。
How do I run a script after installation? 安装后如何运行脚本?
To run your own script after installation, you can create a file called install.bat
and place it in a folder together with any additional files it needs (software to be installed for example). Then bind that folder in your compose file like this:
要在安装后运行自己的脚本,您可以创建一个名为 install.bat
的文件,并将其与它需要的任何其他文件(例如要安装的软件)一起放在一个文件夹中。然后在 compose 文件中绑定该文件夹,如下所示:
volumes:
- /home/user/example:/oem
The example folder /home/user/example
will be copied to C:\OEM
during installation and the containing install.bat
will be executed during the last step.
在安装过程中,示例文件夹 /home/user/example
将被复制到 C:\OEM
,而包含install.bat
将在最后一步中执行。
How do I perform a manual installation? 如何执行手动安装?
It’s best to stick to the automatic installation, as it adjusts various settings to prevent common issues when running Windows inside a virtual environment.
最好坚持自动安装,因为它会调整各种设置以防止在虚拟环境中运行 Windows 时出现常见问题。
However, if you insist on performing the installation manually, add the following environment variable to your compose file:
但是,如果您坚持手动执行安装,请将以下环境变量添加到您的 compose 文件中:
environment:
MANUAL: "Y"
How do I change the amount of CPU or RAM? 如何更改 CPU 或 RAM 的数量?
By default, the container will be allowed to use a maximum of 2 CPU cores and 4 GB of RAM.
默认情况下,容器最多允许使用 2 个 CPU 内核和 4 GB RAM。
If you want to adjust this, you can specify the desired amount using the following environment variables:
如果要调整此值,可以使用以下环境变量指定所需的数量:
environment:
RAM_SIZE: "8G"
CPU_CORES: "4"
How do I configure the username and password? 如何配置用户名和密码?
By default, a user called Docker
is created during the installation, with an empty password.
默认情况下,在安装过程中会创建一个名为 Docker
的用户,其密码为空。
If you want to use different credentials, you can change them in your compose file:
如果您想使用不同的凭证,可以在 compose 文件中更改它们:
environment:
USERNAME: "bill"
PASSWORD: "gates"
How do I select the Windows language? 如何选择 Windows 语言?
By default, the English version of Windows will be downloaded. But you can add the LANGUAGE
environment variable to your compose file, in order to specify an alternative language:
默认情况下,将下载英文版的 Windows。但是你可以将 LANGUAGE
环境变量添加到 compose 文件中,以便指定替代语言:
environment:
LANGUAGE: "French"
You can choose between: 🇦🇪 Arabic, 🇧🇬 Bulgarian, 🇨🇳 Chinese, 🇭🇷 Croatian, 🇨🇿 Czech, 🇩🇰 Danish, 🇳🇱 Dutch, 🇬🇧 English, 🇪🇪 Estonian, 🇫🇮 Finnish, 🇫🇷 French, 🇩🇪 German, 🇬🇷 Greek, 🇮🇱 Hebrew, 🇭🇺 Hungarian, 🇮🇹 Italian, 🇯🇵 Japanese, 🇰🇷 Korean, 🇱🇻 Latvian, 🇱🇹 Lithuanian, 🇳🇴 Norwegian, 🇵🇱 Polish, 🇵🇹 Portuguese, 🇷🇴 Romanian, 🇷🇺 Russian, 🇷🇸 Serbian, 🇸🇰 Slovak, 🇸🇮 Slovenian, 🇪🇸 Spanish, 🇸🇪 Swedish, 🇹🇭 Thai, 🇹🇷 Turkish and 🇺🇦 Ukrainian.
您可以选择: 🇦🇪 阿拉伯语, 🇧🇬 保加利亚语, 🇨🇳 中文, 🇭🇷 克罗地亚语, 🇨🇿 捷克语, 🇩🇰 丹麦语, 🇳🇱 荷兰语, 🇬🇧 英语, 🇪🇪 爱沙尼亚语, 芬兰语, 🇫🇷 🇫🇮 法语, 🇩🇪 德语, 🇬🇷 希腊语, 🇮🇱 希伯来语, 🇭🇺 匈牙利语, 🇮🇹 意大利语, 🇯🇵 日语, 🇰🇷 韩语, 🇱🇻 拉脱维亚语, 🇱🇹 立陶宛语, 🇳🇴 挪威语, 🇵🇱 波兰语, 🇵🇹 葡萄牙语, 🇷🇴 罗马尼亚语, 🇷🇺 俄语, 🇷🇸 塞尔维亚语, 🇸🇰 斯洛伐克语、🇸🇮斯洛文尼亚语、🇪🇸西班牙语、🇸🇪瑞典语、🇹🇭泰语、🇹🇷土耳其语和🇺🇦乌克兰语。
How do I select the keyboard layout? 如何选择键盘布局?
If you want to use a keyboard layout or locale that is not the default for your selected language, you can add the KEYBOARD
and REGION
variables with a culture code, like this:
如果要使用不是所选语言的默认键盘布局或区域设置,则可以添加带有区域性代码的 KEYBOARD
和 REGION
变量,如下所示:
environment:
REGION: "en-US"
KEYBOARD: "en-US"
Note 注意
Changing these values will have no effect after the installation has been performed already. Use the control panel inside Windows in that case.
在执行安装后,更改这些值将不起作用。在这种情况下,请使用 Windows 中的控制面板。
How do I connect using RDP? 如何使用 RDP 进行连接?
The web-viewer is mainly meant to be used during installation, as its picture quality is low, and it has no audio or clipboard for example.
Web 查看器主要用于安装过程中,因为它的图像质量很低,并且没有音频或剪贴板。
So for a better experience you can connect using any Microsoft Remote Desktop client to the IP of the container, using the username Docker
and by leaving the password empty.
因此,为了获得更好的体验,您可以使用任何 Microsoft 远程桌面客户端连接到容器的 IP,使用用户名 Docker
并将密码留空。
There is a RDP client for Android available from the Play Store and one for iOS in the Apple Store. For Linux you can use FreeRDP and on Windows just type mstsc
in the search box.
Play 商店中提供了一个适用于 Android 的 RDP 客户端,Apple Store 中提供了一个适用于 iOS 的 RDP 客户端。对于 Linux,您可以使用 FreeRDP,在 Windows 上只需在搜索框中键入 mstsc
即可。
How do I assign an individual IP address to the container? 如何为容器分配单个 IP 地址?
By default, the container uses bridge networking, which shares the IP address with the host.
默认情况下,容器使用网桥网络,它与主机共享 IP 地址。
If you want to assign an individual IP address to the container, you can create a macvlan network as follows:
如果要为容器分配单个 IP 地址,可以按如下方式创建 macvlan 网络:
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:
创建网络后,将 compose 文件更改为如下所示:
services:
windows:
container_name: windows
..<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.
由于 macvlan 的设计不允许两者之间通信,因此无法从 Docker 主机访问此 IP 地址。如果这是一个问题,则需要创建第二个 macvlan 作为解决方法。
How can Windows acquire an IP address from my router? Windows 如何从我的路由器获取 IP 地址?
After configuring the container for macvlan, it is possible for Windows to become part of your home network by requesting an IP from your router, just like a real PC.
为 macvlan 配置容器后,Windows 可以通过从路由器请求 IP 来成为您家庭网络的一部分,就像真正的 PC 一样。
To enable this mode, add the following lines to your compose file:
要启用此模式,请将以下行添加到您的 compose 文件中:
environment:
DHCP: "Y"
devices:
- /dev/vhost-net
device_cgroup_rules:
- 'c *:* rwm'
Note 注意
In this mode, the container and Windows will each have their own separate IPs.
在此模式下,容器和 Windows 将各自拥有自己的单独 IP。
How do I add multiple disks? 如何添加多个磁盘?
To create additional disks, modify your compose file like this:
要创建其他磁盘,请按如下方式修改 compose 文件:
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:
可以通过将磁盘设备添加到你的 compose 文件中来直接传递磁盘设备:
devices:
- /dev/sdb:/disk1
- /dev/sdc:/disk2
Use /disk1
if you want it to become your main drive (which will be formatted during installation), and use /disk2
and higher to add them as secondary drives (which will stay untouched).
如果您希望 /disk1
成为您的主驱动器(将在安装过程中格式化),请使用 /disk2
及更高版本将它们添加为辅助驱动器(将保持不变)。
How do I pass-through a USB device? 如何通过 USB 设备?
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:
要传递 USB 设备,首先通过 lsusb
命令查找其供应商和产品 ID,然后将它们添加到您的 compose 文件中,如下所示:
environment:
ARGUMENTS: "-device usb-host,vendorid=0x1234,productid=0x1234"
devices:
- /dev/bus/usb
Important 重要
If the device is a USB disk drive, please wait until after the installation is completed before connecting it. Otherwise the installation may fail, as the order of the disks can get rearranged.
如果设备是 USB 磁盘驱动器,请等到安装完成后再连接。否则,安装可能会失败,因为磁盘的顺序可能会重新排列。
转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 vault@coolxy.cn