Windows安装Docker(Docker Desktop)

一、Windows安装Docker简明步骤

在 Windows 上安装 Docker 的简要步骤如下:


1. 检查系统要求

  • 操作系统 :Windows 10/11(64位)专业版/企业版/教育版(家庭版需通过 WSL 2 安装)。
  • 启用虚拟化
    • 确保 BIOS 中启用 虚拟化技术(VT-x/AMD-V)
    • 开启 Hyper-VWSL 2(Windows 功能中勾选)。

2. 安装 WSL 2(若未启用)

  • 以管理员身份打开 PowerShell,运行:

    powershell 复制代码
    wsl --install
  • 重启电脑。


3. 下载 Docker Desktop


4. 运行安装程序

  • 双击下载的 .exe 文件,按向导安装。

5. 启动 Docker Desktop

  • 安装完成后,桌面会出现快捷方式,双击启动。
  • 首次启动会提示登录(可选跳过)。

6. 验证安装

  • 打开 PowerShell 或命令提示符,输入:

    bash 复制代码
    docker --version
    docker run hello-world
  • 若显示版本信息并运行测试容器成功,则安装完成。


常见问题

  • 家庭版用户:需先安装 WSL 2,再通过 Docker Desktop 的 WSL 2 后端运行。
  • 报错处理:若提示虚拟化未开启,检查 BIOS 设置或 Hyper-V/WSL 是否启用。

按照以上步骤操作,即可在 Windows 上顺利使用 Docker。

二、安装过程示例

官网下载 Docker Desktop

Docker官网:https://www.docker.com/

下载后的安装包:

运行安装程序

按向导安装

  • 双击下载的 .exe 文件,按向导安装。


重启计算机

必须重启Windows计算机,才能完成安装。点击 Close and restart ,重启计算机。

Docker订阅服务协议

重启后自动弹出如下界面,本例选择 Accept 接收。

注意:按照协议,公司使用可能是要订阅费的,请谨慎处理。

完成 Docker Desktop 设置

本例选择推荐设置。

登录页面(可选跳过)

  • 首次启动会提示登录(可选跳过)。

本例点击了 不登录直接继续

调查问卷(可选跳过)

调查问卷,本例选择了点击右上角 skip 跳过。

显示异常:Docker Engine stopped

Docker Desktop 无法加载页面,提示:Docker Engine stopped

怀疑是 WSL 问题。

更新 WSL

查看 WSL 是否已开启

更新 WSL

cmd 复制代码
wsl --update

更新成功:

查看 WSL 版本

cmd 复制代码
wsl -v

WSL 更新后,重启计算机

WSL 更新后,重启计算机,会出现如下提示:

弹窗报错

可能出现如下弹窗报错,没有影响,可点击 Quit,直接退出 Docker Desktop 。

An unexpected error occurred

Docker Desktop encountered an unexpected error and needs to close.

Search our troubleshooting documentation ⁠ to find a solution or workaround. Alternatively, you can gather a diagnostics report and submit a support request or GitHub issue.

running engine: waiting for the Docker API: engine linux/wsl failed to run: starting WSL engine: error spotted in wslbootstrap log: "[2025-03-29T18:01:28.754905126Z][wsl-bootstrap][F] expected digest f3c9ec4c42d0ae2bddc360d5dac0063f310aaa0482da7ca0e019076746d56e9a actual digest 11d07f99d28b0af861fe8a9f333916e4f38af11362fbf3bf36d6da03f6dae956"

Read our policy for uploaded diagnostic data⁠

以管理员身份运行 Docker Desktop:成功

这次启动成功了。

验证安装:显示版本信息

docker -v

docker version

powershell 复制代码
PS D:\> docker version
Client:
 Version:           28.0.1
 API version:       1.48
 Go version:        go1.23.6
 Git commit:        068a01e
 Built:             Wed Feb 26 10:41:52 2025
 OS/Arch:           windows/amd64
 Context:           desktop-linux

Server: Docker Desktop 4.39.0 (184744)
 Engine:
  Version:          28.0.1
  API version:      1.48 (minimum version 1.24)
  Go version:       go1.23.6
  Git commit:       bbd0a17
  Built:            Wed Feb 26 10:41:16 2025
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.7.25
  GitCommit:        bcc810d6b9066471b0b6fa75f557a15a1cbf31bb
 runc:
  Version:          1.2.4
  GitCommit:        v1.2.4-0-g6c52b3f
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

验证安装:运行容器

拉取镜像(失败)

powershell 复制代码
PS D:\> docker pull hello-world
Using default tag: latest
Error response from daemon: Get "https://registry-1.docker.io/v2/": context deadline exceeded

遇到Docker拉取镜像时出现 context deadline exceeded 错误,通常是由于网络连接问题导致无法访问Docker Hub。

配置Docker镜像加速器(国内用户推荐),修改Docker配置文件 (daemon.json),添加国内镜像源(如阿里云、腾讯云)。

配置Docker镜像

在 Docker Desktop 的 Settings 界面中选择 Docker Engine 选项卡。

如果没有配置过镜像,原配置json中是没有 "registry-mirrors" 字段部分的,新增内容在最后加上。

点击 Apply & Restart 按钮重启Docker。

配置示例:

json 复制代码
{
    "builder": {
        "gc": {
            "defaultKeepStorage": "20GB",
            "enabled": true
        }
    },
    "experimental": false,
    "registry-mirrors": [
        "Docker镜像URL"
    ]
}

拉取镜像(成功)

powershell 复制代码
PS D:\> docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
e6590344b1a5: Pull complete
Digest: sha256:7e1a4e2d11e2ac7a8c3f768d4166c2defeb09d2a750b010412b6ea13de1efb19
Status: Downloaded newer image for hello-world:latest
docker.io/library/hello-world:latest

查看镜像:docker images

powershell 复制代码
PS D:\> docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE  
hello-world   latest    74cc54e27dc4   2 months ago   10.1kB

创建和启动容器:docker run

docker run:根据指定的镜像创建和启动容器。

powershell 复制代码
PS D:\> 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/

查看镜像和容器

查看镜像

查看容器

相关推荐
tryCbest1 天前
Windows和Linux设置Https(SSL)访问
linux·windows·https
致宏Rex1 天前
Docker 完整教程(3,4) | 网络与挂载
运维·docker·容器
不语n1 天前
Windows+Docker+AI开发板打造智能终端助手
python·docker·树莓派·香橙派·dify·ollama·ai开发板
荣光波比1 天前
Docker(三)—— Docker Compose 编排与 Harbor 私有仓库实战指南
运维·docker·容器·云计算
落日漫游1 天前
DockerCE与cri-docker核心区别解析
运维·docker·kubernetes
努力搬砖的咸鱼1 天前
Docker 三剑客:镜像、容器、仓库
docker·云原生·容器
奔跑吧邓邓子1 天前
【C++实战(68)】从0到1:C++跨平台开发之Windows API深度实战
c++·windows·实战·跨平台·windows api
名誉寒冰1 天前
# 深入理解Linux内核与用户态通信:Netlink机制实战
linux·服务器·windows
byte轻骑兵2 天前
Windows 安全分割利器:strtok_s () 详解
c语言·开发语言·windows·安全
iHero2 天前
【Jitsi Meet】阿里云Docker安装Jitsi Meet后的调整
阿里云·docker·云计算