wsl 安装

参考链接: https://learn.microsoft.com/zh-cn/windows/wsl/install

  1. 通过命令行安装
wsl --update
wsl -v -l
wsl --install

wsl & docker 迁移

WSL发行版默认都是安装在C盘,在%LOCALAPPDATA%/Docker/wsl目录 docker的运行数据、镜像文件都存在%LOCALAPPDATA%/Docker/wsl/data/ext4.vhdx中,这对C盘空间紧张的人非常不友好。。。

提供一个powershell脚本

# wsl2_move_docker_image.ps1 # Docker 镜像存储位置一键迁移脚本(适用于 WSL2 版本) 
# # Powershell Script 3.0+ # --------------------------------------------------------------------------------------- 
# 脚本使用方式(需使用管理员权限执行): # .\wsl2_move_docker_image.ps1 -target "D:\wsl\docker" 
# --------------------------------------------------------------------------------------- 
# # target: 期望迁移的目录 
param([string]$target="D:\Documents\UbuntuWSL") 

Write-Host "Stop docker ..." 
net stop "com.docker.service" 

Write-Host "Stop wsl ..." 
wsl --shutdown 

Write-Host "Move docker-desktop-data image ..." 
wsl --export docker-desktop-data $target\tmp\docker-desktop-data.tar 
wsl --unregister docker-desktop-data 
wsl --import docker-desktop-data $target\data\ $target\tmp\docker-desktop-data.tar --version 2 
Remove-Item $target\tmp\docker-desktop-data.tar -recurse 

Write-Host "Move docker-desktop image ..." 
wsl --export docker-desktop $target\tmp\docker-desktop.tar 
wsl --unregister docker-desktop wsl --import docker-desktop $target\distro\ $target\tmp\docker-desktop.tar --version 2 
Remove-Item $target\tmp\docker-desktop.tar -recurse 

Write-Host "Finish."

--完--