适用于 Linux 的 Windows 子系统可让开发人员按原样运行 GNU/Linux 环境 - 包括大多数命令行工具、实用工具和应用程序 - 且不会产生传统虚拟机或双启动设置开销。
WSL2 给了在 Windows 更接近原生 Linux 的体验,使得 Docker 现在完全可以通过 WSL2 来原生运行。
设置国内镜像软件源
# Debian
sudo sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
# Ubuntu
sudo sed -i 's/archive.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
# Refreshes apt repos and update
sudo apt update && sudo apt upgrade
安装 DOCKER 引擎
# Installs Docker CE
curl -sSL https://get.daocloud.io/docker | sh
# Set Registry mirrors
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s https://registry.hub.docker.com
设置 DOCKER 开机自启
- 启用微软官方支持的
systemd
echo -e "[boot]\nsystemd=true" | sudo tee -a /etc/wsl.conf
# 配置后需要宿主机通过 `wsl --shutdown`命令关闭wsl,来进行wsl的完整重启
- 启用 docker 服务
# service enable
systemctl enable docker.service
# service start
systemctl start docker.service
宿主机设置 WSL 开机自启
- 在 Windows 中创建脚本
linux-start.vbs
Set ws = WScript.CreateObject("WScript.Shell")
ws.run "wsl -d ubuntu -u root",vbhide
- 移动到 Windows 开机启动项
Win+R 输入 shell:startup 将新建脚本拖入到打开的文件夹中
相关资源