Docker Desktop + WSL 2 (Windows Subsystem for Linux) 安装记录
第一步:安装 WSL 2 核心
Docker Desktop 在 Windows 10 上依赖 WSL 2 才能获得最佳性能。
开始前,先大概看一遍微软官方 Windows Subsystem for Linux 文档
以管理员身份(Run as Administrator) 打开 PowerShell
输入以下命令并回车:
PowerShell
wsl --install # 是全自动的,它会自动从网上下载 Linux 的 Windows 子系统(WSL)内核并静默安装。
- 注意:如果系统提示无法识别该命令,说明您的 Windows 版本较老,需要更新 Windows 或手动开启“适用于 Linux 的
Windows 子系统”功能。
WSL 安装命令对比分析
| 命令 | 安装方式 | 特点 |
|---|---|---|
| wsl --install | Microsoft Store | 自动安装依赖组件(如虚拟机平台) 通过应用商店推送更新 适用于大多数用户 |
| wsl --install --web-download | 在线下载 | 从官方源下载发行版包(如 Ubuntu) 跳过应用商店安装流程 需手动运行 wsl --update 检查更新适用于网络受限环境或需自定义安装路径 |
PS C:WINDOWSsystem32> wsl --list --online # 查看可选择的Linux发行版
The following is a list of valid distributions that can be installed.
The default distribution is denoted by '*'. # 带星号的表示默认安装选项
Install using 'wsl --install -d ' .
NAME FRIENDLY NAME
* Ubuntu Ubuntu
Debian Debian GNU/Linux
kali-linux Kali Linux Rolling
Ubuntu-20.04 Ubuntu 20.04 LTS
Ubuntu-22.04 Ubuntu 22.04 LTS
Ubuntu-24.04 Ubuntu 24.04 LTS
OracleLinux_7_9 Oracle Linux 7.9
OracleLinux_8_10 Oracle Linux 8.10
OracleLinux_9_5 Oracle Linux 9.5
openSUSE-Leap-15.6 openSUSE Leap 15.6
SUSE-Linux-Enterprise-15-SP6 SUSE Linux Enterprise 15 SP6
openSUSE-Tumbleweed openSUSE Tumbleweed
示例对比
powershell
# 通过 Store 安装 Ubuntu
wsl --install -d Ubuntu # 这里加不加 -d Ubuntu 参数其实一样,但是这种写法符合规范!
wsl --install -d Ubuntu-22.04 # 根据项目需求谨慎选择,避免潜在的兼容性问题,比如Python、GCC (C编译器) 和 Glibc 的默认版本等
# 通过 Web 下载安装 Ubuntu
wsl --install --web-download -d Ubuntu # 注意:新版本 --location 参数 支持指定 Linux 发行版的安装路径,下面会谈到……
因为本机C盘空间有限,所以直接把 Ubuntu-22.04 安装到D盘,由于本机的 WSL 版本不支持 --location 参数
- 这里还有一种方法,就是到微软官网下载Linux 内核更新包 ➡️ 安装最新版本的 WSL 2 Linux 内核,
Windows系统 x86架构 版本 WSL2 Linux 内核更新包适用于 x64 计算机 下载到本地是一个.msi格式的安装文件wsl_update_x64.msi,双击安装完,就可以继续wsl --install --web-download -d Ubuntu-22.04 --location 'D:WSLUbuntu2204'命令,指定Linux发行版的安装路径
# 因为本机C盘空间有限,所以想直接把 Ubuntu-22.04 安装到D盘,由于本机的 WSL 版本不支持 `--location` 参数
PS C:WINDOWSsystem32> wsl --install --web-download -d Ubuntu-22.04 --location 'D:WSLUbuntu2204'
Copyright (c) Microsoft Corporation. All rights reserved.
Usage: wsl.exe [Argument]
Arguments:
--install <Options>
Install Windows Subsystem for Linux features. If no options are specified,
the recommended features will be installed along with the default distribution.
To view the default distribution as well as a list of other valid distributions,
use 'wsl --list --online'.
Options:
--distribution, -d [Argument]
Specifies the distribution to be downloaded and installed by name.
Arguments:
A valid distribution name (not case sensitive).
Examples:
wsl --install -d Ubuntu
wsl --install --distribution Debian
--inbox
Install the optional Windows feature instead of the version available via the Microsoft Store.
--no-distribution
Do not install a distribution (cannot be used with --distribution).
--no-launch, -n
Do not launch the distribution after install.
--web-download
Download the most recent version of WSL from the internet instead of the Microsoft Store.
--list, -l [Options]
Lists distributions.
Options:
--online, -o
Displays a list of available distributions for install with 'wsl --install'.
--status
Show the status of Windows Subsystem for Linux.
--help
Display usage information.
这里使用 --no-distribution 参数,仅安装 WSL 核心,不安装Linux发行版,后面手动安装
# 所以使用 `--no-distribution` 参数,仅安装 WSL 核心,不安装Linux发行版,后面手动安装 Ubuntu-22.04
PS C:WINDOWSsystem32> wsl --install --web-download --no-distribution
Installing: Virtual Machine Platform
Virtual Machine Platform has been installed.
Installing: Windows Subsystem for Linux
Downloading: Windows Subsystem for Linux
[ 0.3% ] #显示下载进度
Windows Subsystem for Linux has been installed.
The requested operation is successful. Changes will not be effective until the system is rebooted.
安装完重启电脑
PS C:WINDOWSsystem32> wsl --set-default-version 2 # 设置默认使用 WSL 2
- 具体参考微软官方 比较 WSL 1 和 WSL 2 文档,里面介绍的更详细,而且文档言语直白,很好理解
使用 wsl --import 方式安装 Ubuntu
在 WSL 的手动安装步骤页面,找到你想要安装的 Linux 发行版

文件名通常是:Ubuntu2204-221101.AppxBundle 或类似名称。
这里推荐使用IDM下载,IDM会自动解析为 Ubuntu2204-221101.zip 下载到本地;
下完后抽取里面Ubuntu_2204.1.7.0_x64.appx 修改后缀为 Ubuntu_2204.1.7.0_x64.zip ;
再用压缩软件打开,如下图:

提取里面的install.tar.gz文件
打开powershell,执行下面的命令
PS C:WINDOWSsystem32> wsl --import Ubuntu-22.04 D:WSLUbuntu2204 D:WSLinstall.tar.gz --version 2
这种方法也适用于安装 Microsoft 商店 WSL 提供的 Linux 发行版之外的其他版本,比如CentOS等。
PS C:WINDOWSsystem32> wsl.exe --status
Default Distribution: Ubuntu-22.04 # 显示Ubuntu已安装成功
Default Version: 2
PS C:WINDOWSsystem32> wsl.exe --list --verbose
NAME STATE VERSION
* Ubuntu-22.04 Stopped 2
PS C:WINDOWSsystem32> wsl --terminate Ubuntu-22.04 # 关闭指定 Linux发行版
PS C:WINDOWSsystem32> wsl -d Ubuntu-22.04
root@DESKTOP:/mnt/c/WINDOWS/system32# useradd -m -G sudo -s /bin/bash # 手动创建一个普通用户,比如 user01
root@DESKTOP:/mnt/c/WINDOWS/system32# passwd
New password:
Retype new password:
passwd: password updated successfully
root@DESKTOP:/mnt/c/WINDOWS/system32# echo "[user]" > /etc/wsl.conf # 设置默认登录用户
root@DESKTOP:/mnt/c/WINDOWS/system32# echo "default=" >> /etc/wsl.conf # 下次启动使用这个新用户,而不是 root。
root@DESKTOP:/mnt/c/WINDOWS/system32# exit
logout
PS C:WINDOWSsystem32> wsl --terminate Ubuntu-22.04
The operation completed successfully.
PS C:WINDOWSsystem32> wsl -d Ubuntu-22.04
To run a command as administrator (user "root"), use "sudo " .
See "man sudo_root" for details.
user01@DESKTOP:/mnt/c/WINDOWS/system32$ # 看到 user01@ 开头,说明设置默认用户成功
第二步:安装 Docker Desktop

到 Docker 官网,下载 Docker Desktop Installer.exe
# “以管理员身份” 执行带参数的安装命令
Start-Process -FilePath ".Docker Desktop Installer.exe" -ArgumentList "install --quiet --accept-license --backend=wsl-2 --no-desktop-shortcut --installation-dir=D:DockerApp --wsl-default-data-root=D:ProgramDataDockerData --windows-containers-default-data-root=D:ProgramDataDockerWindowsContainersData" -Wait
命令参数解释:
• Start-Process 是 PowerShell 中用于启动外部程序或文档的命令。
• -FilePath 指定要启动的可执行文件或文档的完整路径。
• -ArgumentList 传递给目标程序的参数列表。
• 参数格式:在单字符串中参数需用引号包裹,多个参数用空格分隔。
• --quiet 静默安装,可加可不加,不加的话,可能会弹出交互窗口。
• --accept-license 是 PowerShellGet 模块中的参数,用于自动接受脚本依赖模块的许可证,可简化脚本安装流程,提升自动化效率。
• --backend=wsl-2 指定使用 WSL 2,这也是 Docker 官方推荐默认选项,参看下面截图。
• --no-desktop-shortcut 取消勾选快捷方式,添加这个参数,安装程序不会在桌面添加快捷方式,参看下面截图。
•--installation-dir: Docker 的程序文件会安装到 D:DockerApp
•--wsl-default-data-root: 最关键的,未来数十 GB 数据。所有的镜像、容器数据都会自动存放到 D:ProgramDataDockerData
• --windows-containers-default-data-root 这个选项决定了你是否要在 Linux 容器和 Windows 容器之间进行切换。
(注意:根据你的实际需要选择,如果你的开发项目只需要 Linux 容器,通常不需要勾选此项)
参数补充: --windows-***-root 只是提前指定了 “如果以后使用 Windows 容器,数据放哪儿”,它本身不代表开启这个功能。
注意:此处需要使用双斜杠 D:ProgramDataDockerWindowsContainersData
• -Wait: 命令会等待安装完成才结束。

命令执行后,可能不会有太多弹窗,或者只会弹出一个请求权限的窗口,点击“是”。
因为本机安装之前没有创建安装目录,所以报错:[Installer][I] No installation found,下面是在网上找的别的网友的安装日志:
这个问题在 Docker 官网也没找到解释,官网交互式安装指导显示 Docker Desktop 默认安装到 C:Program FilesDockerDocker 目录下,可能安装程序里面的逻辑是检查 C:Program FilesDockerDocker 目录是否存在,如果不存在则创建,然后继续安装程序;但是我们指定安装到 D盘,这与安装程序的检查目录逻辑不符,所以提示 No installation found,手动在D盘创建安装目录之后,则安装程序按照命令继续运行直到安装完成。
当然,这也只是猜测。
Microsoft Windows [版本 10.0.19045.6093]
(c) Microsoft Corporation。保留所有权利。
D:Download>start /w "" "Docker Desktop Installer.exe" install -accept-license --installation-dir="D:Program FilesDockerDesktop" --wsl-default-data-root="D:Program FilesDockerDesktopdata" --windows-containers-default-data-root="D:Program FilesDockerDesktop"
-------------------------------------------------------------------------------->8
Version: 4.43.2 (199162)
Sha1:
Started on: 2025/07/19 06:22:04.260
Resources: D:Downloadresources
OS: Windows 10 Pro
Edition: Professional
Id: 2009
Build: 19045
BuildLabName: 19041.1.amd64fre.vb_release.191206-1406
File: C:UsersXAppDataLocalDockerinstall-log.txt
CommandLine: "Docker Desktop Installer.exe" install -accept-license --installation-dir="D:Program FilesDockerDesktop" --wsl-default-data-root="D:Program FilesDockerDesktopdata" --windows-containers-default-data-root="D:Program FilesDockerDesktop"
You can send feedback, including this log file, at https://github.com/docker/for-win/issues
[2025-07-19T06:22:04.390353000Z][Installer][I] No installation found # 本机没有安装目录,需要在执行命令之前手动创建安装目录
[2025-07-19T06:22:04.406348000Z][ManifestLoader][I] Install path is D:Program FilesDockerDesktop.
[2025-07-19T06:22:04.534028200Z][ProcessEnvironmentDetector][I] Not run as admin, relaunching with UAC prompt
-------------------------------------------------------------------------------->8
Version: 4.43.2 (199162)
Sha1:
Started on: 2025/07/19 06:22:14.857
Resources: D:Downloadresources
OS: Windows 10 Pro
Edition: Professional
Id: 2009
Build: 19045
BuildLabName: 19041.1.amd64fre.vb_release.191206-1406
File: C:ProgramDataDockerDesktopinstall-log-admin.txt
CommandLine: "D:DownloadDocker Desktop Installer.exe" "install" -package "res:DockerDesktop" --installation-dir="D:Program FilesDockerDesktop" --wsl-default-data-root="D:Program FilesDockerDesktopdata" --windows-containers-default-data-root="D:Program FilesDockerDesktop" --relaunch-as-admin
You can send feedback, including this log file, at https://github.com/docker/for-win/issues
[2025-07-19T06:22:15.105339000Z][Installer][I] No installation found
[2025-07-19T06:22:15.144509200Z][ManifestLoader][I] Install path is D:Program FilesDockerDesktop.
[2025-07-19T06:22:15.356448500Z][AdminInstallHandler][I] Running admin installation
[2025-07-19T06:22:15.782308700Z][InstallWorkflow][I] Using package: res:DockerDesktop
[2025-07-19T06:22:15.785257500Z][InstallWorkflow][I] Downloading
[2025-07-19T06:22:19.745013000Z][InstallWorkflow][I] Extracting manifest
[2025-07-19T06:22:23.260815000Z][InstallWorkflow][I] Manifest found: version=199162, displayVersion=4.43.2, channelUrl=https://desktop-stage.docker.com/win/main/amd64/appcast.xml
[2025-07-19T06:22:23.261773300Z][InstallWorkflow][I] Checking prerequisites
[2025-07-19T06:22:23.745276900Z][InstallWorkflow][I] Prompting for optional features
[2025-07-19T06:22:32.489638300Z][InstallWorkflow][I] Selected backend mode: wsl-2
[2025-07-19T06:22:32.491642300Z][InstallWorkflow][I] Unpacking artifacts
[2025-07-19T06:25:27.083713400Z][InstallWorkflow][I] Deploying component Docker.Installer.CreateGroupAction
[2025-07-19T06:25:45.163046500Z][InstallWorkflow][I] Deploying component Docker.Installer.AddToGroupAction
[2025-07-19T06:25:54.264798700Z][InstallWorkflow][I] Deploying component Docker.Installer.EnableFeaturesAction
[2025-07-19T06:25:54.353797800Z][InstallWorkflow-EnableFeaturesAction][I] Required features: VirtualMachinePlatform, Microsoft-Windows-Subsystem-Linux
[2025-07-19T06:25:56.872105300Z][InstallWorkflow][I] Deploying component Docker.Installer.ServiceAction
[2025-07-19T06:25:56.882393500Z][InstallWorkflow-ServiceAction][I] Removing service
[2025-07-19T06:25:56.887103000Z][InstallWorkflow-ServiceAction][I] Creating service
[2025-07-19T06:25:56.902109400Z][InstallWorkflow][I] Deploying component Docker.Installer.ShortcutAction
[2025-07-19T06:25:56.992049300Z][InstallWorkflow-ShortcutAction][I] Creating shortcut: C:ProgramDataMicrosoftWindowsStart MenuDocker Desktop.lnk/Docker Desktop
[2025-07-19T06:25:57.905381900Z][InstallWorkflow][I] Deploying component Docker.Installer.ShortcutAction
[2025-07-19T06:25:57.906388000Z][InstallWorkflow-ShortcutAction][I] Creating shortcut: C:UsersXIAOWEIDesktopDocker Desktop.lnk/Docker Desktop
[2025-07-19T06:25:57.908476800Z][InstallWorkflow][I] Deploying component Docker.Installer.AutoStartAction
[2025-07-19T06:25:57.912383300Z][InstallWorkflow][I] Deploying component Docker.Installer.PathAction
[2025-07-19T06:25:59.113103500Z][InstallWorkflow][I] Deploying component Docker.Installer.ExecAction
[2025-07-19T06:25:59.131984500Z][InstallWorkflow-ExecAction][I] Running: D:Program FilesDockerDesktopInstallerCli.exe -i with timeout=-1
[2025-07-19T06:26:09.178305900Z][InstallWorkflow][I] Registering product
[2025-07-19T06:26:09.186301700Z][RegisterProductStep][I] Creating installation manifest
[2025-07-19T06:26:09.188299800Z][RegisterProductStep][I] Registering product information
[2025-07-19T06:26:09.681866100Z][RegisterProductStep][I] Registering docker-desktop url-protocol
[2025-07-19T06:26:09.684825800Z][RegisterProductStep][I] Registering integration information
[2025-07-19T06:26:09.693941400Z][InstallWorkflow][I] Saving C:ProgramDataDockerDesktopinstall-settings.json
[2025-07-19T06:26:09.879824800Z][InstallWorkflow][I] Installation succeeded
安装后的检查:
- 检查安装程序目录: 查看文件夹 D:Dockerpp,里面应该有很多 Docker 的 .exe 和 .dll 文件。
- 检查数据存储目录: 查看文件夹 D:ProgramDataDockerData。
注意: 这个文件夹在刚安装完时可能是空的。
当你第一次启动 Docker 并下载镜像(比如运行docker run hello-world)后,这里会出现一个名为 ext4.vhdx 的文件。 - WSL 状态: 打开 PowerShell 运行 wsl -l -v。看到 docker-desktop,说明安装成功 👍 。
PS C:UsersX86_64> wsl --list --verbose
NAME STATE VERSION
4. Ubuntu-22.04 Stopped 2
docker-desktop Stopped 2
PS C:UsersX86_64>
参考
- Windows Subsystem for Linux 文档
- Linux Distribution
- WSL2的安装以及在其下的Ubuntu安装docker、milvus教程
- 安装wsl-Ubuntu到D盘
- 【docker】windows10 docker 安装到D盘
- Docker Desktop 安装到D盘(包括wsl)
- Install Docker Desktop on Windows
- Docker Community Forums - Docker installation directory











