1. 安裝WSL
- WSL 是什么: WSL 是一個在 Windows 上運行 Linux 環境的輕量級工具,它可以讓用戶在 Windows 系統中運行 Linux 工具和應用程序。
- Docker 為什么需要 WSL: Docker 依賴 Linux 內核功能,WSL 2 提供了一個高性能、輕量級的 Linux 內核支持,從而讓 Docker 在 Windows 上運行更加高效。
- 對用戶的好處: 無需安裝笨重的虛擬機,容器性能更好,且與 Windows 主機無縫集成。
1.1 確認CPU已經啟用虛擬化
1.2 管理員身份執行
wsl --install
安裝完畢后重啟電腦,安裝Ubuntu,Windows系統要基于WSL的Linux子系統才能直接裝docker,這里ubuntu就是一個子系統。
wsl --install -d Ubuntu
2. 安裝Hyper-V
因為Windows11 家庭版上沒有Hyper-V服務,所以需要自行安裝
1.1 cmd 輸入 optionalfeatures 來查看Windows功能
2.2 創建一個text文本,拷貝下文:
pushd "%~dp0"
dir /b %SystemRoot%\servicing\Packages\*Hyper-V*.mum >hyper-v.txt
for /f %%i in ('findstr /i . hyper-v.txt 2^>nul') do dism /online /norestart /add-package:"%SystemRoot%\servicing\Packages\%%i"
del hyper-v.txt
Dism /online /enable-feature /featurename:Microsoft-Hyper-V-All /LimitAccess /ALL
2.3 文件名改為hyper.bat,以管理員身份運行,等待安裝完輸入Y,電腦重啟
勾選三項:
- Hyper-V
- 適用于Linux的Windows子系統
- 虛擬機平臺
3. 安裝Docker Desktop
3.1 官網下載
Installer.exe 執行安裝即可:https://docs.docker.com/desktop/setup/install/windows-install/
驗證安裝完成:
docker version
安裝完畢登錄,如果報錯,可能是上述安裝沒有重啟生效,重啟即可。
3.2 配置阿里云鏡像加速
替換并restart
{"builder": {"gc": {"defaultKeepStorage": "20GB","enabled": true}},"experimental": false,"features": {"buildkit": true},"registry-mirrors": ["https://registry.docker-cn.com","http://hub-mirror.c.163.com","https://docker.mirrors.ustc.edu.cn","https://cr.console.aliyun.com","https://mirror.ccs.tencentyun.com"]
}