Windows Server 2019安装Docker搭建Ubuntu虚拟环境

Windows Server 2019安装Docker搭建Ubuntu虚拟环境,第1张

Windows Server 2019安装Docker搭建Ubuntu虚拟环境 背景

组里的服务器都是Windows Server的,但最近要使用的集群构建本地脚本时,需要Ubuntu的环境,装虚拟机的话麻烦,占用空间还大。随想着使用docker加载Ubuntu的镜像,简单且方便。

准确的说,并非一定要使用Ubuntu的环境,而是构建本地脚本时需要一个叫 pwd 的 module,而这个模块仅在 Linux系统中才有,所以只能使用Ubuntu了。

此篇日志被记录的原因还有一个,就是Windows Server 2019如果直接安装桌面版的docker,会由于版本原因报错: “windows 17763 is deprecated docker”, "Docker for Windows doesn't Support your Windows version"。

安装 Docker Desktop for Windows

此部分主要参考:Installing Docker Desktop for Windows and WSL 2

1.安装 WSL2

Windows Subsystem for Linux (WSL) 是在Windows上运行docker桌面版的唯一可行方案。在Windows Pro 也可以用 Hyper-V,,但是现在已被弃用,而 WSL 2几乎可通用。

1.1 安装WSL1

用管理员模式打开 PowerShell , 然后执行:

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

结果应该像这样:

> dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

Deployment Image Servicing and Management tool
Version: 10.0.19041.746

Image Version: 10.0.19042.804

Enabling feature(s)
[==========================100.0%==========================]
The operation completed successfully.

1.2 打开 Virtual Machine feature

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

结果显示:

> dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
Deployment Image Servicing and Management tool
Version: 10.0.19041.746

Image Version: 10.0.19042.804

Enabling feature(s)
[==========================100.0%==========================]
The operation completed successfully.

1.3 重启

一定要重启,否则后面的设置会报错。

1.4 安装 WSL 2 更新

下载 the WSL2 Linux kernel update package for x64 machines ,并安装。

如果之前没有重启,会报错:

 1.5 设置 WSL 2 为默认模式

依旧在 PowerShell  中,执行:

wsl --set-default-version 2
2. 安装 Windows 的 docker 桌面版

Head to the Docker Desktop website and download the Installer for Windows.

全选,并默认安装,即可成功。

 

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4663594.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-06
下一篇 2022-11-06

发表评论

登录后才能评论

评论列表(0条)

保存