在腾讯云 Windows Server 2022 实例上安装 Docker,推荐使用 Docker Desktop for Windows(需启用 WSL2)或 Docker Engine(Windows 容器)。由于 Windows Server 2022 默认不支持 WSL2(除非已安装并配置),更稳妥的方式是直接安装 Docker Engine for Windows(基于 Hyper-V 的 Windows 容器)。以下是完整步骤:
✅ 前提条件
- 系统要求:
- Windows Server 2022(64 位)
- 已启用 Hyper-V 功能(必须)
- 已启用 容器支持(Container Feature)
- 内存建议 ≥ 4GB,磁盘空间 ≥ 20GB
- 网络要求:
- 确保能访问公网下载镜像(可配置国内镜像提速,如阿里云、腾讯云镜像站)
- 权限:
- 使用管理员账户操作
🔧 步骤一:启用必要功能(PowerShell 以管理员运行)
# 启用 Hyper-V 和容器功能
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName Containers -All -NoRestart
# 重启后生效(建议立即重启)
Restart-Computer
💡 若提示“需要重启”,请先执行
Restart-Computer,再继续后续步骤。
📦 步骤二:下载并安装 Docker Engine for Windows
方法 A:通过官方 MSI 安装包(推荐)
-
访问 Docker 官方发布页:
https://docs.docker.com/desktop/install/windows-install/
→ 选择 “Docker Engine for Windows”(非 Docker Desktop)
或直接下载稳定版 MSI:
https://download.docker.com/win/stable/Docker%20for%20Windows.msi⚠️ 注意:Docker Desktop for Windows 依赖 WSL2,而 Windows Server 2022 默认无 WSL2;若未安装 WSL2 子系统,请使用 Docker Engine(即上述 MSI)。
-
双击
.msi安装:- 勾选 “Install Docker Engine”
- 保持默认选项(自动创建虚拟交换机
nat) - 完成安装后重启服务器(部分版本无需重启,但建议重启确保服务启动)
方法 B:通过 Chocolatey(可选)
# 先安装 Chocolatey(若未安装)
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
# 安装 Docker Engine
choco install docker-engine -y
▶️ 步骤三:验证安装
# 检查 Docker 服务是否运行
Get-Service -Name Docker
# 查看版本
docker --version
docker version
# 测试运行 Hello World(使用 Windows 容器)
docker run hello-world
✅ 成功输出应包含:“Hello from Docker!” 及 “This message shows that your installation appears to be working correctly.”
🌐 步骤四:配置国内镜像提速(可选但强烈推荐)
腾讯云用户可使用 腾讯云容器镜像服务(TCR) 或 阿里云镜像提速。
示例:配置阿里云镜像提速器(需先注册阿里云账号并获取专属提速地址)
-
编辑 Docker 配置文件(首次运行
docker info会生成):$configPath = "C:ProgramDataDockerconfigdaemon.json" if (-not (Test-Path $configPath)) { New-Item -Path $configPath -ItemType File -Force | Out-Null } $json = @" { "registry-mirrors": [ "https://<你的专属提速地址>.mirror.aliyuncs.com" ] } "@ $json | Out-File -FilePath $configPath -Encoding utf8 -Force # 重启 Docker 服务 Restart-Service Docker -
验证:
docker info | Select-String "Registry Mirrors"
📌 替代方案:直接使用腾讯云 TCR 私有仓库 + 公共镜像拉取(如
mcr.microsoft.com可通过全局X_X或 CDN 优化)。
🔐 安全与最佳实践(腾讯云环境特别提示)
| 项目 | 建议 |
|---|---|
| 防火墙 | 仅开放必要端口(如 2375 不暴露公网!建议用 SSH 隧道或内网访问) |
| 用户权限 | 避免将普通用户加入 docker 组(Windows 中为 Docker Users 组),防止提权风险 |
| 日志轮转 | 修改 daemon.json 限制日志大小:"log-driver": "json-file", "log-opts": {"max-size":"10m", "max-file":"3"} |
| 资源隔离 | 对生产容器设置 CPU/内存限制(--cpus, -m) |
| 定期更新 | 关注 Docker 官方公告 及时升级 |
❓ 常见问题排查
| 问题 | 解决方案 |
|---|---|
Cannot connect to the Docker daemon |
检查 Docker 服务状态:Get-Service Docker;尝试 Start-Service Docker |
hyper-v is not enabled |
确认 BIOS 中 VT-x/AMD-V 已开启;重新运行 Enable-WindowsOptionalFeature |
| 拉取镜像超时 | 配置镜像提速器;或临时使用 docker pull --platform windows/amd64 <image> 指定架构 |
| 容器无法联网 | 检查 NAT 虚拟交换机是否正常;重启 Docker 服务可能重建网络 |
需要我提供:
- 自动化部署脚本(PowerShell + Ansible)?
- 如何部署 .NET / Node.js / Java 应用示例?
- 如何配置持久化存储(卷挂载)?
欢迎告诉我具体需求,我可进一步定制方案。
CLOUD技术笔记