在阿里云的 Windows Server 上安装 Docker,需要注意以下几点:
⚠️ 重要提示:Docker 在 Windows 上仅支持 Windows 10 Pro、Windows 11 Pro 或 Windows Server 2016/2019/2022,并且必须是 64 位系统。此外,Docker Desktop 更适合开发环境,而生产环境推荐使用 Docker Engine for Windows Server(通过 PowerShell 安装)。
以下是针对 阿里云 Windows Server 实例(如 Windows Server 2019 或 2022) 安装 Docker 的步骤:
✅ 方法一:使用 PowerShell 安装 Docker Engine(推荐用于服务器)
这是在 Windows Server 上部署 Docker 的标准方式,适用于生产或测试环境。
步骤 1:以管理员身份运行 PowerShell
- 登录阿里云 Windows Server(通过远程桌面 RDP)。
- 打开“开始菜单” → 搜索
PowerShell→ 右键选择“以管理员身份运行”。
步骤 2:安装 OneGet PowerShell 模块(如果未安装)
Install-Module -Name DockerMsftProvider -Repository PSGallery -Force
步骤 3:从 Microsoft 更新源安装 Docker
Install-Package -Name docker -ProviderName DockerMsftProvider
这个命令会下载并安装最新稳定版的 Docker Engine。
步骤 4:重启计算机(必须)
Restart-Computer -Force
步骤 5:验证安装
重启后再次打开管理员 PowerShell,运行:
docker --version
你应该看到类似输出:
Docker version 20.10.xx, build xxxxx
还可以运行测试容器:
docker run hello-world:nanoserver
注意:Windows 容器需要使用 Nano Server 或 Server Core 镜像,不能运行 Linux 容器(除非开启特殊模式,但性能差且不推荐)。
✅ 方法二:安装 Docker Desktop(仅限特定版本)
⚠️ 注意:Docker Desktop 不支持所有 Windows Server 版本,它主要面向 Windows 10/11 Pro 和部分企业版。
如果你的 Windows Server 支持 WSL2 和 Hyper-V(例如 Windows Server 2019/2022 with Desktop Experience),可以尝试安装 Docker Desktop。
步骤:
-
下载 Docker Desktop for Windows:
👉 https://www.docker.com/products/docker-desktop/ -
上传安装包到你的阿里云服务器(可通过 FTP、浏览器或阿里云 Workbench)。
-
安装前确保启用以下功能:
# 启用 Hyper-V 和 Containers 功能
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V, Containers -All
-
重启服务器。
-
运行 Docker Desktop 安装程序并完成安装。
-
启动 Docker Desktop 并登录。
🛠️ 常见问题与注意事项
| 问题 | 解决方案 |
|---|---|
Install-Module : The term 'Install-Module' is not recognized |
先安装 PowerShell 包管理模块:Install-BoxstarterPackage -PackageName NuGet 或升级 PowerShell 到 5.1+ |
| 安装失败 / 网络超时 | 使用国内镜像源或手动下载 .cab 包离线安装 |
| 无法拉取镜像 | 检查网络,配置镜像提速器(参考阿里云容器镜像服务) |
| Windows 容器 vs Linux 容器 | 默认是 Windows 容器,切换需右键托盘图标 → Switch to Linux containers(但性能较差) |
🔧 配置阿里云镜像提速器(提升拉取速度)
- 登录 阿里云控制台
- 进入「容器镜像服务」→ 「镜像工具」→ 「镜像提速器」
- 获取你的专属提速地址,如:
https://xxxxx.mirror.aliyuncs.com
配置 Docker daemon:
编辑或创建配置文件:
# 创建或修改 daemon.json
Set-Content -Path "$env:ProgramDataDockerconfigdaemon.json" -Value @"
{
"registry-mirrors": ["https://xxxxx.mirror.aliyuncs.com"]
}
"@
然后重启 Docker 服务:
Restart-Service docker
✅ 总结
| 目标 | 推荐方式 |
|---|---|
| 生产环境 Windows Server 上运行容器 | 使用 PowerShell 安装 Docker Engine |
| 开发/测试,图形化操作 | 尝试 Docker Desktop(需满足系统要求) |
| 提速镜像拉取 | 配置阿里云镜像提速器 |
如有具体错误信息,欢迎提供,我可以帮你进一步排查。
秒懂云