【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

版權所有,如需轉載請注明出處。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM