当前位置: 首页 > news >正文

Win10安装DockerDesktop踩坑记

1、软件和环境准备

  • Win10系统(Windows PowerShell)系统自带

  • 原神启动bushi;Microsoft-Hyper-V 、VirtualMachinePlatform、Microsoft-Windows-Subsystem-Linux 启动 (要重启电脑)

  • wsl.2.5.7.0.x64.msi (依赖环境)

  • wsl_update_x64.msi (依赖环境)

  • Ubuntu24.04LTS (CanonicalGroupLimited.Ubuntu24.04LTS_2404.1.26.0_neutral_~_79rhkp1fndgsc.AppxBundle)(依赖环境)

  • Docker Desktop_4.41.2_Machine_x64_en.exe (这个最后安装,最终成品)

官方的环境要求:https://docs.docker.com/desktop/setup/install/windows-install/

WSL version 2.1.5 or later.
Windows 11 64-bit: Home or Pro version 22H2 or higher, or Enterprise or Education version 22H2 or higher.
Windows 10 64-bit: Minimum required is Home or Pro 22H2 (build 19045) or higher, or Enterprise or Education 22H2 (build 19045) or higher.
Turn on the WSL 2 feature on Windows. For detailed instructions, refer to the Microsoft documentation.
The following hardware prerequisites are required to successfully run WSL 2 on Windows 10 or Windows 11:
64-bit processor with Second Level Address Translation (SLAT)
4GB system RAM
Enable hardware virtualization in BIOS/UEFI. For more information, see Virtualization.
For more information on setting up WSL 2 with Docker Desktop, see WSL.
  • wsl版本 >= 2.1.5

  • win10版本 >=  build 19045

2、Win10环境检查

检查win10环境,PowerShell管理员运行,

PS C:\Users\mfc> Get-WmiObject Win32_OperatingSystem | Select Caption, Version, BuildNumberCaption                     Version    BuildNumber
-------                     -------    -----------
Microsoft Windows 10 专业版 10.0.19045 19045PS C:\Users\mfc>

刚好满足最低配置,不然要升级版本

3、启动Microsoft-Hyper-V 、VirtualMachinePlatform、Microsoft-Windows-Subsystem-Linux(后面要重启电脑)

# 1. 启用 Microsoft-Hyper-V
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All# 2. 启用 VirtualMachinePlatform(虚拟机平台)
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -All# 3. 启用 Microsoft-Windows-Subsystem-Linux(WSL 核心)
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux -All

验证

Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V
Get-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform
Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

# 最后:重启电脑

Restart-Computer

详细过程:

Windows PowerShell
版权所有 (C) Microsoft Corporation。保留所有权利。尝试新的跨平台 PowerShell https://aka.ms/pscore6                                                                                                                                                                                                PS C:\Users\mfc> Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All                              Path          :
Online        : True
RestartNeeded : FalsePS C:\Users\mfc> Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-VFeatureName      : Microsoft-Hyper-V
DisplayName      : Hyper-V 平台
Description      : 提供了可以用来创建和管理虚拟机及其资源的服务。
RestartRequired  : Possible
State            : Enabled
CustomProperties :PS C:\Users\mfc>
Windows PowerShell
版权所有 (C) Microsoft Corporation。保留所有权利。尝试新的跨平台 PowerShell https://aka.ms/pscore6                                                                                                                                                                                                PS C:\Users\mfc> Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -All                         Path          :
Online        : True
RestartNeeded : FalsePS C:\Users\mfc> Get-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatformFeatureName      : VirtualMachinePlatform
DisplayName      : 虚拟机平台
Description      : 为虚拟机启用平台支持
RestartRequired  : Possible
State            : Enabled
CustomProperties :PS C:\Users\mfc>
Windows PowerShell
版权所有 (C) Microsoft Corporation。保留所有权利。尝试新的跨平台 PowerShell https://aka.ms/pscore6                                                                                                                                                                                                PS C:\Users\mfc> Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux -All              Path          :
Online        : True
RestartNeeded : FalsePS C:\Users\mfc> Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-LinuxFeatureName      : Microsoft-Windows-Subsystem-Linux
DisplayName      : 适用于 Linux 的 Windows 子系统
Description      : 提供服务和环境以在 Windows 上运行本机用户模式 Linux shell 和工具。
RestartRequired  : Possible
State            : Enabled
CustomProperties :ServerComponent\Description : 提供服务和环境以在 Windows 上运行本机用户模式 Linux shell 和工具。ServerComponent\DisplayName : 适用于 Linux 的 Windows 子系统ServerComponent\Id : 1033ServerComponent\Type : FeatureServerComponent\UniqueName : Microsoft-Windows-Subsystem-LinuxServerComponent\Deploys\Update\Name : Microsoft-Windows-Subsystem-LinuxPS C:\Users\mfc>

重启电脑后,进行wsl安装。

4、wsl下载和安装

这里的坑非常多,最终确认一版能用的,还是用离线安装的方式。在线安装各种失败。

下载安装:wsl.2.5.7.0.x64.msi 

  • https://github.com/microsoft/WSL/releases/download/2.5.7/wsl.2.5.7.0.x64.msi

文档地址:https://github.com/microsoft/WSL/releases

下载安装:wsl_update_x64.msi  

  • https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi

文档地址:https://learn.microsoft.com/zh-cn/windows/wsl/install-manual

下载msi后直接安装或者修复

检查wsl版本 wsl --version

Windows PowerShell
版权所有 (C) Microsoft Corporation。保留所有权利。尝试新的跨平台 PowerShell https://aka.ms/pscore6PS C:\Users\mfc> wsl --version
WSL 版本: 2.5.7.0
内核版本: 6.6.87.1-1
WSLg 版本: 1.0.66
MSRDC 版本: 1.2.6074
Direct3D 版本: 1.611.1-81528511
DXCore 版本: 10.0.26100.1-240331-1435.ge-release
Windows: 10.0.19045.5854
PS C:\Users\mfc>

5、下载 Linux 分发版。

应用商店link地址 https://apps.microsoft.com/detail/9nz3klhxdjp5?hl=zh-cn&gl=CN,不在这里下载,复制地址后。

访问:https://store.rg-adguard.net/   再去 搜索上面的link下载

File:

Expire:

SHA-1:

Size:

CanonicalGroupLimited.Ubuntu24.04LTS_2404.1.26.0_neutral_~_79rhkp1fndgsc.appxbundle

2025-06-14 11:53:37 GMT

5b03d9bb7f9ed3944913e18f0af24d51184a972d

681.47 MB

http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice/files/f8e26723-41b2-4117-9296-2410e88dd677?P1=1749902017&P2=404&P3=2&P4=br6GJOrf8E6htcobPUbDUTBRYecUapwgLz6XPtORcytTz93WMZUXYf9VQMEkNWzOyuiJt19bD1xHfIhCqvN2zQ%3d%3d

直接用迅雷下载

下载后文件目录安装

Windows PowerShell

Add-AppxPackage .\CanonicalGroupLimited.Ubuntu24.04LTS_2404.1.26.0_neutral_~_79rhkp1fndgsc.AppxBundle

安装时要设置用户名和密码,不能是root。我设置的是wslroot / wslroot 。

 设置wsl默认版本为2

# 查看所有 WSL 发行版                  
wsl --list --verbose
# 设置 Ubuntu-24.04 使用 WSL 2         
wsl --set-version Ubuntu-24.04 2
# 设置 docker-desktop 使用 WSL 2       
wsl --set-version docker-desktop 2
# 设置默认发行版                        
wsl --set-default Ubuntu-24.04
# 设置默认 WSL 版本为 2                 
wsl --set-default-version 2

我已经设置过了,部分提示是这样的

PS C:\Users\mfc> wsl --list --verboseNAME              STATE           VERSION
* Ubuntu-24.04      Stopped         2docker-desktop    Stopped         2
PS C:\Users\mfc> wsl --set-version Ubuntu-24.04 2
有关与 WSL 2 关键区别的信息,请访问 https://aka.ms/wsl2正在进行转换,这可能需要几分钟时间。该分发已是请求的版本。
错误代码: Wsl/Service/WSL_E_VM_MODE_INVALID_STATE
PS C:\Users\mfc> wsl --set-version docker-desktop 2
有关与 WSL 2 关键区别的信息,请访问 https://aka.ms/wsl2正在进行转换,这可能需要几分钟时间。该分发已是请求的版本。
错误代码: Wsl/Service/WSL_E_VM_MODE_INVALID_STATE
PS C:\Users\mfc> wsl --set-default Ubuntu-24.04
操作成功完成。
PS C:\Users\mfc> wsl --set-default-version 2
有关与 WSL 2 关键区别的信息,请访问 https://aka.ms/wsl2操作成功完成。
PS C:\Users\mfc>


6、安装Docker Desktop

应用商店link地址 https://apps.microsoft.com/detail/xp8cbj40xlbwkx?hl=en-GB&gl=GB,不在这里下载,复制地址后。

访问:https://store.rg-adguard.net/   再去 搜索上面的link下载

File:  

SHA-256:

Docker Desktop_4.41.2_Machine_x64_en.exe

2fb4c553656c51f0dcfd5eaf12250b0b5cf1a2e61c24f63873092df46957c8d3

https://desktop.docker.com/win/main/amd64/191736/Docker%20Desktop%20Installer.exe

直接用迅雷下载。

Docker Desktop_4.41.2_Machine_x64_en.exe  直接安装。

7、使用Docker Desktop 的问题

Docker Desktop 桌面图标,直接启动时发现会提示“WSL启动期间出错”

处理,手动启动wsl,在启动Docker Desktop。

# 列出所有已安装的 WSL 发行版, 包括它们是正在运行 (Running) 还是已经停止 (Stopped),以及配置使用的 WSL 版本(1 或 2)。
wsl --list --verbose# 关闭所有正在运行的 WSL 实例
wsl --shutdown# 启动默认或指定的 WSL 发行版
wsl

正常应该是`Running`状态

PS C:\Users\mfc> wsl -l -vNAME              STATE           VERSION
* Ubuntu-24.04      Running         2docker-desktop    Running         2
PS C:\Users\mfc>

8、Docker Desktop其他配置

设置mirrors镜像源:Docker Desktop--设置--Docker Engine

{"registry-mirrors": ["https://docker.m.daocloud.io","https://docker.rainbond.cc","https://docker.lmirror.top"],"builder": {"gc": {"defaultKeepStorage": "20GB","enabled": true}},"experimental": false
}

指定镜像磁盘目录:Docker Desktop--设置--Resources Advanced--Disk image location

D:\docker-local-images\DockerDesktopWSL

9、验证Docker Desktop是否启动成功

Windows PowerShell,wsl -l -v

PS C:\Users\mfc> wsl -l -vNAME              STATE           VERSION
* Ubuntu-24.04      Running         2docker-desktop    Running         2
PS C:\Users\mfc>

普通cmd命令


# 使用命令行工具验证 Docker 版本
docker --version# 运行一个测试容器, 没有镜像会先去下载,这里会慢一些
docker run hello-world# 检查正在运行的容器
docker ps# 如果你刚刚运行了 hello-world 容器,由于它是短生命周期的任务,可能已经结束了。要查看所有容器(包括已停止的),可以加上 -a 
docker ps -a

示例:

# 第一次运行会去拉镜像
C:\Users\mfc>docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
e6590344b1a5: Pull complete
Digest: sha256:940c619fbd418f9b2b1b63e25d8861f9cc1b46e3fc8b018ccfe8b78f19b8cc4f
Status: Downloaded newer image for hello-world:latestHello from Docker!
This message shows that your installation appears to be working correctly.
...
C:\Users\mfc>docker --version
Docker version 28.1.1, build 4eba377C:\Users\mfc>docker run hello-worldHello from Docker!
This message shows that your installation appears to be working correctly.To generate this message, Docker took the following steps:1. The Docker client contacted the Docker daemon.2. The Docker daemon pulled the "hello-world" image from the Docker Hub.(amd64)3. The Docker daemon created a new container from that image which runs theexecutable that produces the output you are currently reading.4. The Docker daemon streamed that output to the Docker client, which sent itto your terminal.To try something more ambitious, you can run an Ubuntu container with:$ docker run -it ubuntu bashShare images, automate workflows, and more with a free Docker ID:https://hub.docker.com/For more examples and ideas, visit:https://docs.docker.com/get-started/C:\Users\mfc>docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMESC:\Users\mfc>docker ps -a
CONTAINER ID   IMAGE         COMMAND    CREATED         STATUS                      PORTS     NAMES
1bb748d5a076   hello-world   "/hello"   7 seconds ago   Exited (0) 10 seconds ago             focused_carson
b7252a3191a0   hello-world   "/hello"   5 hours ago     Exited (0) 5 hours ago                peaceful_montalcini
c22b7879b0ab   hello-world   "/hello"   5 hours ago     Exited (0) 5 hours ago                pensive_bohrC:\Users\mfc>

PowerShell 验证 Docker 与 WSL 2 的集成

# PowerShell 中启动你的 WSL 默认的发行版
wsl
# 使用命令行工具验证 Docker 版本
docker --version
# 要查看所有容器(包括已停止的)
docker ps -a

示例:

PS C:\Users\mfc> wsl
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.wslroot@DESKTOP-GUUQS9V:/mnt/c/Users/mfc$ docker --version
Docker version 28.1.1, build 4eba377
wslroot@DESKTOP-GUUQS9V:/mnt/c/Users/mfc$ docker ps -a
CONTAINER ID   IMAGE         COMMAND    CREATED              STATUS                          PORTS     NAMES
1bb748d5a076   hello-world   "/hello"   About a minute ago   Exited (0) About a minute ago             focused_carson
b7252a3191a0   hello-world   "/hello"   5 hours ago          Exited (0) 5 hours ago                    peaceful_montalcini
c22b7879b0ab   hello-world   "/hello"   5 hours ago          Exited (0) 5 hours ago                    pensive_bohr
wslroot@DESKTOP-GUUQS9V:/mnt/c/Users/mfc$

10、踩坑后记

折腾了4小时,总算搞定。

各种环境报错,主要时间花在处理WSL的问题,还好没有重装系统。

结束。

相关文章:

  • C++斯特林数在C++中的数学理论与计算实现1
  • YOLOv8模型剪枝实战:DepGraph(依赖图)方法详解
  • Win系统权限提升篇AD内网域控NetLogonADCSPACKDCCVE漏洞
  • create_react_agent + MCP tools
  • synchronized和ReentrantLock的区别
  • 【论文阅读】Qwen2.5-VL Technical Report
  • Vue 3 九宫格抽奖系统,采用优雅的 UI 设计和流畅的动画效果
  • 打卡Day53
  • 在tensorrt engine中提高推理性能小记
  • 网络安全防护:Session攻击
  • 【python深度学习】Day53对抗生成网络
  • Vue3 + TypeScript + Element Plus 设置表格行背景颜色
  • 第十七章 Linux之大数据定制篇——Shell编程
  • 【C语言】C语言发展历史、特点及其应用
  • SpringBoot源码解析(十二):@ConfigurationProperties配置绑定的底层转换
  • 树莓派智能小车红外避障实验指导书
  • DeepSeek介绍
  • 【Canvas与曲线】使用贝塞尔二次曲线实现平滑过渡的内旋拼合三角形
  • 人工智能学习13-Numpy-规律数组生成
  • Python训练营-Day31-文件的拆分和使用
  • 公司网站制作商/站长之家网站模板
  • 单页网站上传教程/宣传推广策略
  • 做三盛石材网站的公司/sem运营有出路吗
  • 网站关键词优化怎么做/汽车营销策划方案ppt
  • 德州极速网站建设/公司网站怎么注册
  • 德州建设信息网站/西安seo关键词查询