搜尋結果

×

在win11安裝wsl和Docker安裝教學

教你在 Windows 11 上安裝 WSL 和 Docker,並介紹 Docker 。

因為我之前的教學文都有附上我安裝好的Docker image,
但有滿多同學不太知道Docker是什麼? 甚至還沒有安裝過,
於是想要先出基礎教學讓大家知道Docker怎麼安裝。😊

我之前教學過的兩個Docker image在這邊附上,
歡迎使用bert_huggingfaceollama_flask

此文章也有發表在Medium上 >>

一、安裝 WSL (Windows Subsystem for Linux)

1. 啟用 WSL 功能

開啟 PowerShell

  1. 以系統管理員身份運行 PowerShell。
  2. 在「開始」菜單中搜索「PowerShell」,右鍵點擊選擇「以系統管理員身份運行」。

啟用 WSL

在 PowerShell 中輸入以下命令來啟用 WSL 和虛擬機平臺

wsl --install

這個時候你會看到如下~

PS C:\Users\AS> wsl --install
已安裝 Windows 子系統 Linux 版。
以下是可安裝之有效發佈的清單。
使用 'wsl --install -d <Distro>' 安裝。

NAME                                   FRIENDLY NAME
Ubuntu                                 Ubuntu
Debian                                 Debian GNU/Linux
kali-linux                             Kali Linux Rolling
Ubuntu-18.04                           Ubuntu 18.04 LTS
Ubuntu-20.04                           Ubuntu 20.04 LTS
Ubuntu-22.04                           Ubuntu 22.04 LTS
Ubuntu-24.04                           Ubuntu 24.04 LTS
OracleLinux_7_9                        Oracle Linux 7.9
OracleLinux_8_7                        Oracle Linux 8.7
OracleLinux_9_1                        Oracle Linux 9.1
openSUSE-Leap-15.5                     openSUSE Leap 15.5
SUSE-Linux-Enterprise-Server-15-SP4    SUSE Linux Enterprise Server 15 SP4
SUSE-Linux-Enterprise-15-SP5           SUSE Linux Enterprise 15 SP5
openSUSE-Tumbleweed                    openSUSE Tumbleweed

這個時候請你挑一個你想要的版本安裝,像我想要下載Ubuntu-22.04的版本,那我的指令就是>>

wsl — install -d Ubuntu-22.04

安裝中..

PS C:\Users\AS> wsl --install -d Ubuntu-22.04
正在安裝:Ubuntu 22.04 LTS
已完成安裝 Ubuntu 22.04 LTS。
正在啟動 Ubuntu 22.04 LTS...

這時候你可以在 開始> 看到安裝好的Ubuntu出現了~

錯誤出現:WslRegisterDistribution failed with error

這時候你點進去會出現下面的錯誤 > 參考官方文獻 - 下載 Linux 核心更新包

Installing, this may take a few minutes...
WslRegisterDistribution failed with error: 0x800701bc
Error: 0x800701bc WSL 2 ???????????????????? visit https://aka.ms/wsl2kernel

Press any key to continue...

原因是因為缺了 WSL2 Linux 的更新套件,這時候請去設定的進階選項把”接收其他MS產品的更新“功能給打開。

之後再去按下檢查更新,確認WSL更新完成後,再次進入安裝好的Ubuntu中

可以看到Ubuntu可以跑了~ 而且他會叫你設定帳號密碼!!

Installing, this may take a few minutes...
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
Enter new UNIX username:
New password:
Retype new password:
passwd: password updated successfully
Installation successful!
適用於 Linux 的 Windows 子系統現已在 Microsoft Store 中提供!
您可以執行 'wsl.exe --update' 進行升級或瀏覽 https://aka.ms/wslstorepage
從 Microsoft Store 安裝 WSL 將會為您提供最新的 WSL 更新,且更快速。
如需詳細資訊,請瀏覽 https://aka.ms/wslstoreinfo

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

Welcome to Ubuntu 22.04.3 LTS (GNU/Linux 5.10.102.1-microsoft-standard-WSL2 x86_64)

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

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

二、安裝 Docker

1. 下載 Docker Desktop

  • 訪問 Docker 官方網站
    打開瀏覽器,訪問 Docker 官方網站 - Docker Desktop 下載頁面

  • 下載 Docker Desktop
    點擊「Download for Windows」按鈕下載 Docker Desktop 安裝程式。

2. 安裝 Docker Desktop

  • 運行安裝程式
    下載完成後,運行安裝程式並按照提示完成安裝。

  • 重啟電腦
    安裝完成後,重啟電腦以應用更改。

3. 配置 Docker Desktop

啟動 Docker Desktop

  • 從「開始」菜單中啟動 Docker Desktop。

在這步驟時請務必先確認你的 WSL 已經安裝完成,且已經啟用。

如果你的 WSL 沒有安裝完成,那麼你的 Docker Desktop 會出現 Docker Engine stopped 的字樣唷~

驗證 Docker 安裝

  • 打開 PowerShell 或 WSL 終端,輸入Docker命令驗證安裝是否成功:

      docker --version
    

這樣,你就完成了在 Windows 11 上安裝 WSL 和 Docker 的步驟。

下一篇會教導大家Docker的使用教學~

    喜歡 Weiberson 的文章嗎?在這裡留下你的評論!本留言區支援 Markdown 語法