踩完坑之后的总结: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
相关推荐
赛博云推-Twitter热门霸屏工具1 小时前
Twitter自动发推工具怎么选?从人工运营到自动化管理的实践分析
运维·自动化·twitter
玖釉-1 小时前
Vulkan 示例解析:pipelines.cpp 如何在一个 Render Pass 中切换多条 Graphics Pipeline
c++·windows·算法·图形渲染
dshudsnb1 小时前
4种实用方法,快速完成新旧电脑数据迁移
运维·服务器·电脑
sxdtzhp1 小时前
定时任务避峰运行:远离整点,保障系统稳定运行
运维·软件工程·定时任务·crontab
chushiyunen2 小时前
localwp+wordpress个人建站
windows
benjiangliu2 小时前
LINUX系统-18-EXT系列文件系统(三)
linux·运维·chrome
zhangfeng11332 小时前
,在slurm中也能安装ubundu了,Singularity(现叫 Apptainer)不需要root权限的容器方案,对比docker
运维·人工智能·机器学习·docker·容器
一只鹿鹿鹿2 小时前
网络安全和安防建设方案(doc文件)
大数据·运维·网络·物联网·安全
LJianK12 小时前
服务器高 CPU 排查方法
linux·运维·服务器