安裝WSL2 與 Docker

roccqqck
3 min readMay 23, 2020

Windows Subsystem for Linux 2 (WSL2)終於正式上線 無聊寫個中文安裝教學

首先win10 要是2004以上 19041 build以上

請去windows update 更新win10 2004

(win10 1903 1909也支援WSL2了, 請去windows update 小版本更新)

安裝有linux kernel的WSL2

reference https://docs.microsoft.com/en-us/windows/wsl/install-win10

Powershell 以系統管理員執行

  • 打開WSL功能
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
  • 打開virtualmachine platform功能
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

或者透過控制台開啟這兩個功能

https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi

點開wsl_update_x64.msi 直接安裝

  • Powershell 將WSL預設版本調成WSL2
wsl --set-default-version 2

點開microsoft store安裝 你要的WSL版本 https://aka.ms/wslstore

我是選ubuntu20.04 設帳號密碼

再來就可以用WSL2了

C槽會mount在 WSL的路徑

ls /mnt/c 

所以檔案系統是互通的

安裝win10 docker desktop

reference https://docs.docker.com/docker-for-windows/wsl/

  • 一定要安裝最新版

https://download.docker.com/win/stable/Docker%20Desktop%20Installer.exe

安裝時勾選WSL2 Intergration不需要開啟hyperV就能用

win10家用版也能用

安裝完點開Docker Desktop 設定確認一下 WSL2功能開啟

  • 打開WSL2的terminal (WSL2不需要另外安裝linux版docker-ce)
docker versionsudo usermod -aG docker $USER  

docker pull hello-world

再來就可以開始使用WSL2 linux kernel的docker

再也不需要用win10 hyperV docker

目前vscode有支援WSL開發

https://code.visualstudio.com/blogs/2020/03/02/docker-in-wsl2

記得裝外掛

win10筆電終於可以很方便使用linux開發了

但是記住他不是拿來取代 linux server的

--

--