踩完坑之后的总结:Windows安装docker

首先docker安装程序已经下载好:Docker Desktop Installer.exe

直接双击安装只能装 C 盘,须要用命令行指定路径安装。

1、在 D 盘提前建好文件夹(路径不要中文、空格):

bash 复制代码
D:\software\Docker\DockerData
D:\software\Docker\DockerDesktop

2、管理员身份打开 PowerShell:

win+x->终端(管理员)(A)

3、进入安装包所在目录,例如:

bash 复制代码
cd D:\software

4、执行安装命令:

bash 复制代码
& ".\Docker Desktop Installer.exe" install `
-accept-license `
--installation-dir="D:\software\Docker\DockerDesktop" `
--wsl-default-data-root="D:\software\Docker\DockerData"

这一步会踩坑,豆包最开始给的命令是:

bash 复制代码
.\DockerDesktopInstaller.exe install `
-accept-license `
--installation-dir="D:\software\Docker\DockerDesktop" `
--wsl-default-data-root="D:\software\Docker\DockerData"

因为下载的安装包是Docker Desktop Installer.exe,文件名是带空格的,所以必须加英文双引号 "" 包住整个路径 / 文件名和前面的.\,像这样:

bash 复制代码
".\Docker Desktop Installer.exe"

但是这样还不行,会报错:

bash 复制代码
PS D:\software> ".\Docker Desktop Installer.exe" install `
>> -accept-license `
>> --installation-dir="D:\software\Docker\DockerDesktop" `
>> --wsl-default-data-root="D:\software\Docker\DockerData"
所在位置 行:1 字符: 34
+ ".\Docker Desktop Installer.exe" install `
+                                  ~~~~~~~
表达式或语句中包含意外的标记"install"。
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken

需要在命令的最前面加:&,这样才可以:

bash 复制代码
PS D:\software> & ".\Docker Desktop Installer.exe" install `
>> -accept-license `
>> --installation-dir="D:\software\Docker\DockerDesktop" `
>> --wsl-default-data-root="D:\software\Docker\DockerData"
PS D:\software> ----------------------------------------------------------------->8
Version: 4.75.0 (227598)
Sha1:
Started on: 2026/06/02 14:42:49.445
Resources: C:\Users\xxx\AppData\Local\Temp\DockerDesktopInstallers\1780411368009720100\resources
OS: Windows 10 Pro
Edition: Professional
Id: 2009
Build: 26200
BuildLabName: 26100.1.amd64fre.ge_release.240331-1435
File: C:\ProgramData\DockerDesktop\install-log-admin.txt
CommandLine: "C:\Users\x~1\AppData\Local\Temp\DockerDesktopInstallers\1780411368009720100\Docker Desktop Installer.exe" install -package C:\Users\x~1\AppData\Local\Temp\DockerDesktopInstallers\1780411368009720100\DockerDesktop.d4w -accept-license --installation-dir=D:\software\Docker\DockerDesktop --wsl-default-data-root=D:\software\Docker\DockerData
You can send feedback, including this log file, at https://dockr.ly/desktop-feedback
[2026-06-02T14:42:51.514698200Z][Installer][I] No installation found

从日志可以看出,

(1)本次带参数的静默安装指令已经被程序识别完毕,参数生效了,但还没开始正式安装,弹出图形配置框需要手动确认配置。

(2)D 盘安装路径、数据路径两个参数已经成功写入安装程序,生效了,弹窗只是额外配置,不会覆盖命令里指定的 D 盘路径。

5、在弹出的图形配置框中:

(1)保持:All-users installation(默认选中)

(2)保留勾选:Use WSL2 instead of Hyper-V(适配现有的 Ubuntu2204)

(3)取消勾选:Allow Windows Containers(只用 Linux 容器)

(4)保留:Add shortcut to desktop

(5)直接点右下角 OK → 开始安装

安装后结果:

(1)Docker 程序目录:D:\software\Docker\DockerDesktop

(2)镜像 / 容器数据目录:D:\software\Docker\DockerData

手动配置完图形配置弹窗后,终端打印:

bash 复制代码
[2026-06-02T14:46:05.010260300Z][InstallWorkflow-ShortcutAction][I] Creating shortcut: C:\ProgramData\Microsoft\Windows\Start Menu\Docker Desktop.lnk/Docker Desktop
[2026-06-02T14:46:05.018734200Z][InstallWorkflow][I] Deploying component Docker.Installer.ShortcutAction
[2026-06-02T14:46:05.021741900Z][InstallWorkflow-ShortcutAction][I] Creating shortcut: C:\Users\xxx\Desktop\Docker Desktop.lnk/Docker Desktop
[2026-06-02T14:46:05.025744400Z][InstallWorkflow][I] Deploying component Docker.Installer.AutoStartAction
[2026-06-02T14:46:05.029743000Z][InstallWorkflow][I] Deploying component Docker.Installer.PathAction
[2026-06-02T14:46:05.206065200Z][InstallWorkflow][I] Deploying component Docker.Installer.ExecAction
[2026-06-02T14:46:05.211061200Z][InstallWorkflow-ExecAction][I] Running: D:\software\Docker\DockerDesktop\InstallerCli.exe -i with timeout=-1
[2026-06-02T14:46:06.157948900Z][InstallWorkflow][I] Registering new product
[2026-06-02T14:46:06.158952300Z][RegisterProductStep][I] Registering product information
[2026-06-02T14:46:06.167950000Z][RegisterProductStep][I] Registering docker-desktop url-protocol
[2026-06-02T14:46:06.171951200Z][InstallWorkflow][I] Phase 5: Validation
[2026-06-02T14:46:06.173952700Z][InstallWorkflow][I] Phase 6: Cleanup
[2026-06-02T14:46:06.175951400Z][InstallWorkflow][I] Saving C:\ProgramData\DockerDesktop\install-settings.json
[2026-06-02T14:46:06.185950100Z][InstallWorkflow][I] Installation succeeded

6、重启电脑,需要刷新系统权限、环境变量、WSL 关联。

开机后打开 PowerShell执行:

bash 复制代码
PS C:\Users\xxx> docker --version
Docker version 29.5.2, build 79eb04c

再执行测试容器:

bash 复制代码
docker run hello-world
bash 复制代码
PS C:\Users\xxx> docker run hello-world

Hello 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 the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share 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/

这一步会踩坑,豆包最开始给的镜像是:

打开 Docker Desktop → 点右上角 齿轮(Settings)→Docker Engine

bash 复制代码
{
  "builder": {
    "gc": {
      "defaultKeepStorage": "20GB",
      "enabled": true
    }
  },
  "experimental": false,
  "registry-mirrors": [
    "https://docker.mirrors.ustc.edu.cn",
    "https://mirror.baidubce.com",
    "https://hub-mirror.c.163.com"
  ]
}

然后点右下角 Apply & Restart 等待 Docker 重启完成。

结果还是不行:

bash 复制代码
PS C:\Users\xxx> docker run hello-world
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: failed to resolve reference "docker.io/library/hello-world:latest": failed to do request: Head "https://docker.mirrors.ustc.edu.cn/v2/library/hello-world/manifests/latest?ns=docker.io": dialing docker.mirrors.ustc.edu.cn:443 container via direct connection because Docker Desktop has no HTTPS proxy: connecting to docker.mirrors.ustc.edu.cn:443: dial tcp: lookup docker.mirrors.ustc.edu.cn: no such host

Run 'docker run --help' for more information

于是再次修改,打开 Docker Desktop → 右上角 齿轮(Settings) → 左侧 Docker Engine:

bash 复制代码
{
  "builder": {
    "gc": {
      "defaultKeepStorage": "20GB",
      "enabled": true
    }
  },
  "experimental": false,
  "registry-mirrors": [
    "https://docker.xuanyuan.me",
    "https://docker.m.daocloud.io",
    "https://mirror.ccs.tencentyun.com"
  ]
}

结果OK

bash 复制代码
PS C:\Users\xxx> docker run hello-world

Hello 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 the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share 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/

6、这里说明一下:

(1)docker images 只会看到一条 hello-world,本地缓存永久保存。

(2)docker run = 用镜像新建一个独立容器实例,每执行一次 docker run hello-world → 新建一个全新容器,所以面板列表越来越多。 hello-world 程序运行打印一句话就自动退出停止,所以状态不是 running。

7、常用清理命令:

(1)删除所有已停止的无用容器(一键清空面板列表)

bash 复制代码
docker container prune

回车输入y,界面里一堆 hello-world 容器瞬间全清。

(2)想只运行一次、用完自动删除容器,加参数 --rm,运行结束自动销毁容器,不会残留列表:

bash 复制代码
docker run --rm hello-world

(3)查看本地镜像(验证镜像只存一份)

bash 复制代码
docker images

8、安装完成后关键配置:

(1)打开 Docker 桌面 → Settings → Resources → WSL Integration

(2)打开 Ubuntu-2204 的开关 → Apply & Restart

(3)打开终端,输入docker info验证互通。

bash 复制代码
xxx@DEV-yyy:/mnt/c/Users/xxx$ docker info
Client:
 Version:    29.5.2
 Context:    default
 Debug Mode: false
 Plugins:
  agent: Docker AI Agent Runner (Docker Inc.)
    Version:  v1.57.0
    Path:     /usr/local/lib/docker/cli-plugins/docker-agent
...

9、Enable integration with additional distros → Ubuntu-2204(蓝色已开启)作用:

(1)打开 WSL 终端(wsl进入 ubuntu),直接执行docker images / docker run,和 Windows PowerShell共用同一套镜像、容器

(2)Windows 下载的 Nginx/MySQL 镜像,在 Ubuntu 里直接能用,数据统一存在 D 盘D:\software\Docker\DockerData

(3)不开启 = Ubuntu 内找不到 docker 命令,只能 Windows 用 Docker,下图是不打开和打开Ubuntu-2204前后的对比:

bash 复制代码
xxx@DEV-xxx:/mnt/c/Users/xxx$ docker images

The command 'docker' could not be found in this WSL 2 distro.
We recommend to activate the WSL integration in Docker Desktop settings.

For details about using Docker Desktop with WSL 2, visit:

https://docs.docker.com/go/wsl2/

xxx@DEV-yyy:/mnt/c/Users/xxx$ docker images
                                                                                                    i Info →   U  In Use
IMAGE                ID             DISK USAGE   CONTENT SIZE   EXTRA
hello-world:latest   0e760fdfbc48       25.9kB         9.49kB    U
相关推荐
qq_316411031 小时前
商用冷柜售后报修运维管理系统开发案例
运维
智码看视界2 小时前
Day59-阿里云ACK实战:生产级K8s集群部署与运维
运维·阿里云·kubernetes·k8s·日志监控·容器运维·阿里云ack
码视野3 小时前
基于 Vue3 + Element Plus 的【智慧新能源汽车充电桩运维调度与分时共享租赁系统】设计与实现(附完整源码与PRD)
运维·人工智能·汽车·vue3
qq_426003964 小时前
【UI自动化测试】UI自动化报错解决方案
运维·ui·自动化
网安蟹佬霸4 小时前
WAF绕过技术实战:从规则检测到编码绕过全指南(2026最新版,附Payload集与自动化脚本)
运维·安全·网络安全·架构·自动化·网安
小杨不想秃头4 小时前
信息安全工程师教程第二章密码学
运维·服务器·密码学
I'mChloe4 小时前
WGCLOUD怎么监控多台服务器?从Server、Agent 部署到监控面板实战
运维·服务器
Android系统攻城狮4 小时前
Linux PipeWire深度解析之pw_init调用流程与实战(八十三)
linux·运维·服务器·音频进阶·pipewire音频进阶
国科安芯5 小时前
轨道供电韧性:ASP4644四通道降压架构在低轨卫星平台电源管理中的适用性分析
运维·网络·数据库·嵌入式硬件·架构·状态模式·低轨卫星星座
Python自动化直播6 小时前
周末测试直播自动化时,发现一个棘手的并发问题
运维·自动化