環(huán)境
windows10 2004
前言
一開始是想在自己的電腦上使用docker,所以理所當(dāng)然地裝了docker-desktop,使用過程中碰到了一些坑點(diǎn),比如docker相關(guān)的環(huán)境參數(shù)設(shè)置。然后發(fā)現(xiàn)了wsl的存在,可以在windows中無縫使用操作linux系統(tǒng),所以就上手實(shí)踐了。
安裝wsl及Ubuntu
啟用適用于 Linux 的 Windows 子系統(tǒng)
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
啟用虛擬機(jī)功能
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
下載安裝Linux(這里用的Ubuntu)

下載 Linux 內(nèi)核更新包
網(wǎng)址:https://docs.microsoft.com/zh-cn/windows/wsl/wsl2-kernel

將 WSL 2 設(shè)置為默認(rèn)版本
以管理員的身份打開 PowerShell,然后在安裝新的 Linux 發(fā)行版時(shí)運(yùn)行以下命令,將 WSL 2 設(shè)置為默認(rèn)版本:
wsl --set-default-version 2
在我電腦上不知道為什么命令無效,指定分發(fā)版本后設(shè)置才成功。如果你也不成功,可以查看下方的 “指定Linux 分發(fā)版的 WSL 版本”。
安裝所選的 Linux 分發(fā)
打開 Microsoft Store,并選擇你偏好的 Linux 分發(fā)版。
我選的是ubuntu20.04。
設(shè)置新分發(fā)
為新的 Linux 分發(fā)版創(chuàng)建用戶帳戶和密碼。
將分發(fā)版版本設(shè)置為 WSL 1 或 WSL 2
查看Linux 分發(fā)版的 WSL 版本:
wsl -l -v
指定Linux 分發(fā)版的 WSL 版本:
wsl --set-version <distribution name> <versionNumber>
例如:wsl --set-version Ubuntu-20.04 2,以查看WSL版本時(shí)顯示的linux版本名為準(zhǔn)。
安裝docker
進(jìn)入U(xiǎn)buntu shell
更換Ubuntu源
進(jìn)入源列表文件:
vim /etc/apt/sources.list
替換為阿里云的源(阿里云官方鏡像站):
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted
deb http://mirrors.aliyun.com/ubuntu/ focal universe
deb http://mirrors.aliyun.com/ubuntu/ focal-updates universe
deb http://mirrors.aliyun.com/ubuntu/ focal multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted
deb http://mirrors.aliyun.com/ubuntu/ focal-security universe
deb http://mirrors.aliyun.com/ubuntu/ focal-security multiverse
安裝docker(docker官網(wǎng)教程:https://docs.docker.com/engine/install/ubuntu/)
更新apt軟件包索引并安裝軟件包以允許apt通過HTTPS使用存儲(chǔ)庫(kù):
sudo apt-get update
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
添加Docker的官方GPG密鑰:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
設(shè)置穩(wěn)定的存儲(chǔ)庫(kù):
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
將$(lsb_release -cs)替換為你Ubuntu當(dāng)前分發(fā)版代號(hào),如 focal
安裝DOCKER引擎:
sudo apt-get install docker-ce docker-ce-cli containerd.io
啟動(dòng)docker服務(wù):
sudo service docker start
通過運(yùn)行hello-world 映像來驗(yàn)證是否正確安裝了Docker Engine:
sudo docker run hello-world
通知docker服務(wù):
sudo service docker stop
重啟docker服務(wù):
sudo service docker restart
參考鏈接
https://docs.microsoft.com/zh-cn/windows/wsl/install-win10
http://www.itdecent.cn/p/a20c2d58eaac