一、WSL 安装 Ubuntu20.04
- Win10 启用 WSL
管理员身份运行:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
重启电脑。
开启虚拟器特性
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
下载安装包:
- WSL2 Linux kernel update package for x64 machines
- https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi
设置默认版本:
wsl --set-default-version 2
ref: https://docs.microsoft.com/en-us/windows/wsl/install-win10
打开 Microsoft Store,安装 Ubuntu20.04
启动 Ubuntu20.04,创建账号、密码
安装 Windows Terminal(可选)
用 scoop 安装。
scoop install windows-terminal
windows-terminal 简单设置:
- 启动目录:
//wsl$/Ubuntu-20.04//home/bo
- 字体:
Jetbrains Mono
- 设置源,更新(可选)
打开配置文件: sudo nano /etc/apt/sources.list
, 替换成以下内容:
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
ref: https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/
更新:sudo apt update
升级:sudo apt upgrade
- 安装 ZSH、oh-my-zsh(可选)
-略-
二、安装 Docker
ref: https://docs.docker.com/engine/install/ubuntu/
- 首先更新索引,安装必要的依赖软件,添加新的 HTTPS 软件源
sudo apt update
sudo apt install apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release
- 使用下面的 curl 导入源仓库的 GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
- 添加 Docker APT 软件源
echo \
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
现在,Docker 软件源被启用了,你可以安装软件源中任何可用的 Docker 版本。
- 安装 Docker 最新版本
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
- 运行一下是否安装成功
sudo docker run hello-world
可能或报错:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. > Is the docker daemon running?
再试一下:
sudo systemctl status docker
sudo systemctl status docker
还是报错:
System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is down
原因是 WSL 没有完全实现 Linux 下的 systemctl 的命令, 可以检查一下:
# check if your system is using `systemd` or `sysvinit`
ps -p 1 -o comm=
# If the command doesn't return systemd, and in my case, Ubuntu-20.04 on WSL, the command returned init, then use the command pattern
# start services using sysvinit
service docker start
ref: https://stackoverflow.com/questions/52604068/using-wsl-ubuntu-app-system-has-not-been-booted-with-system-as-init-system-pi
因此,在WSL下 要用以下命令启动 docker。
service docker start
done!