Win10-WSL-Ubuntu20.04-Docker 安装与配置
一、WSL 安装 Ubuntu20.04
- Win10 启用 WSL
 
管理员身份运行:
1  | dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart  | 
重启电脑。
开启虚拟器特性
1  | 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
 
设置默认版本:
1  | 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 安装。
1  | scoop install windows-terminal  | 
windows-terminal 简单设置:
- 启动目录: 
//wsl$/Ubuntu-20.04//home/bo - 字体: 
Jetbrains Mono 
- 设置源,更新(可选)
 
打开配置文件: sudo nano /etc/apt/sources.list, 替换成以下内容:
1  | # 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释  | 
ref: https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/
更新:sudo apt update
升级:sudo apt upgrade
- 安装 ZSH、oh-my-zsh(可选)
 
二、安装 Docker
- 首先更新索引,安装必要的依赖软件,添加新的 HTTPS 软件源
 
1  | sudo apt update  | 
- 使用下面的 curl 导入源仓库的 GPG key
 
1  | curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg  | 
- 添加 Docker APT 软件源
 
1  | echo \  | 
现在,Docker 软件源被启用了,你可以安装软件源中任何可用的 Docker 版本。
- 安装 Docker 最新版本
 
1  | sudo apt-get update  | 
- 运行一下是否安装成功
 
1  | sudo docker run hello-world  | 
可能或报错:
 1 Cannot connect to the Docker daemon at unix:///var/run/docker.sock. > Is the docker daemon running?
再试一下:
1  | sudo systemctl status docker  | 
还是报错:
 1
2 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 的命令, 可以检查一下:
1  | # check if your system is using `systemd` or `sysvinit`  | 
因此,在WSL下 要用以下命令启动 docker。
1  | service docker start  | 
done!