【Docker 】Docker Desktop for Windows(WSL 2)安装

✨Docker for Windows

Install Docker Desktop on Windows | Docker Documentation

官方文档安装教程非常详细,系统配置需求详见官方文档


Windows可选两种方式:

  • WSL 2 backend
  • Hyper-V backend and Windows containers

本教程采用第一种方式安装。


✨安装 WSL 2

WSL 2

参考 Microsoft WSL 官方文档


现在,可以在管理员 PowerShell 或 Windows 命令提示符中输入此命令,然后重启计算机来安装运行适用于 Linux 的 Windows 子系统 (WSL) 所需的全部内容。

wsl --install

此命令将启用所需的可选组件,下载最新的 Linux 内核,将 WSL 2 设置为默认值,并安装 Linux 发行版(默认安装 Ubuntu,请参阅下文更改此设置)。

首次启动新安装的 Linux 发行版时,将打开一个控制台窗口,要求你等待将文件解压缩并存储到计算机上。 未来的所有启动时间应不到一秒。


这里安装WSL感觉比之前安装Kail WSL容易多了= =

一条命令就安装了WSL 2和Ubuntu

详见:【教程】Windows搭建Linux子系统(WSL)详细教程 - 双份浓缩馥芮白 - 博客园 (cnblogs.com)


重启电脑。


检查正在运行的 WSL 版本

可列出已安装的 Linux 发行版,并通过在 PowerShell 或 Windows 命令提示符中输入以下命令来检查每个发行版的 WSL 版本:wsl -l -v

wsl -l -v

请确保安装的是WSL 2

如果需要 安装的是WSL 1

(一般不会出现这种情况 或者是之前已经安装过WSL)

可参考 将版本从 WSL 1 升级到 WSL 2


设置 Linux 用户信息

使用 WSL 安装 Linux 发行版的过程完成后,使用“开始”菜单打开该发行版(默认情况下为 Ubuntu)。 系统将要求你为 Linux 发行版创建“用户名”和“密码”。

  • 用户名密码特定于安装的每个单独的 Linux 分发版,与 Windows 用户名无关。
  • 创建用户名密码后,该帐户将是分发版的默认用户,并将在启动时自动登录。
  • 此帐户将被视为 Linux 管理员,能够运行 sudo (Super User Do) 管理命令。
  • 在 WSL 上运行的每个 Linux 发行版都有其自己的 Linux 用户帐户和密码。 每当添加分发版、重新安装或重置时,都必须配置一个 Linux 用户帐户。

若要更改或重置密码,请打开 Linux 发行版并输入命令:passwd。 系统会要求你输入当前密码,然后要求输入新密码,之后再确认新密码。

如果忘记了 Linux 分发版的密码:

  1. 请打开 PowerShell,并使用以下命令进入默认 WSL 分发版的根目录:wsl -u root

    如果需要在非默认分发版中更新忘记的密码,请使用命令:wsl -d Debian -u root,并将 Debian 替换为目标分发版的名称。

  2. 在 PowerShell 内的根级别打开 WSL 发行版后,可使用此命令更新密码:passwd <username>,其中 <username> 是发行版中帐户的用户名,而你忘记了它的密码。

  3. 系统将提示你输入新的 UNIX 密码,然后确认该密码。 在被告知密码已成功更新后,请使用以下命令在 PowerShell 内关闭 WSL:exit


第一次重启弹出 需要输入默认Unix username 并设置password

之后在Windows Terminal新建标签页中可以看到 Ubuntu

默认以之前设置的用户登录

阅读安装成功提示

To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

Welcome to Ubuntu 20.04 LTS (GNU/Linux 5.10.16.3-microsoft-standard-WSL2 x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Sun Jan 30 14:14:40 CST 2022

  System load:  0.0                Processes:             11
  Usage of /:   0.4% of 250.98GB   Users logged in:       0
  Memory usage: 3%                 IPv4 address for eth0: 172.31.198.140
  Swap usage:   0%


0 updates can be installed immediately.
0 of these updates are security updates.


The list of available updates is more than a week old.
To check for new updates run: sudo apt update


This message is shown once once a day. To disable it please create the
/home/ubuntu/.hushlogin file.

设置root密码

运行以下命令为root设置密码

sudo passwd

✨安装 Docker Desktop for Windows

下载

Get Started with Docker | Docker

或者

Docker Hub

点击下载installer


安装

官方文档安装教程如下

  1. Double-click Docker Desktop Installer.exe to run the installer.

    If you haven’t already downloaded the installer (), you can get it from Docker Hub. It typically downloads to your folder, or you can run it from the recent downloads bar at the bottom of your web browser.Docker Desktop Installer.exe``Downloads

  2. When prompted, ensure the Enable Hyper-V Windows Features or the Install required Windows components for WSL 2 option is selected on the Configuration page.

  3. Follow the instructions on the installation wizard to authorize the installer and proceed with the install.

  4. When the installation is successful, click Close to complete the installation process.

  5. If your admin account is different to your user account, you must add the user to the docker-users group. Run Computer Management as an administrator and navigate to Local Users and Groups > Groups > docker-users. Right-click to add the user to the group. Log out and log back in for the changes to take effect.

如果没有先安装WSL 2这一步的安装界面如下

默认勾选开启 Hyper-V

安装完成

快速入门指南

点击 close and log out

后注销(或者手动重启)


启动 Docker for Windows

同意协议

启动成功后过一下指引

部署完成


在dashboard中可以管理镜像


如果之前是使用 Hyper-V backend

想换成WSL 2可以在设置里勾选 Use the WSL 2 based engine

(这里有说明 WSL 2 比传统的 Hyper-V backend 性能更好)

WSL 2 provides better performance than the legacy Hyper-V backend. Learn more.


✨参考及引用

Install Docker Desktop on Windows | Docker Documentation

安装 WSL | Microsoft Docs

WSL 上的 Docker 容器入门 | Microsoft Docs


⭐转载请注明出处

本文作者:双份浓缩馥芮白

原文链接:https://www.cnblogs.com/Flat-White/p/15857283.html

版权所有,如需转载请注明出处。

posted @ 2022-01-30 17:50  双份浓缩馥芮白  阅读(3190)  评论(0编辑  收藏  举报