WSL配置记录

使用最新版本的WSL,相对更加简单易用

wsl安装

bug 解决:The Windows Subsystem for Linux optional component is not enabled. Please enable it and try again.
在 Windows 11 上安装 Ubuntu 22.04 子系统时遇到的问题和解决方法
使用手动安装可以指定盘的位置
Manual installation steps for older versions of WSL | Microsoft Learn
步骤包括:打开wsl服务、打开虚拟化平台(重启后生效)
下载包,解压第一次,再解压appx(x64)文件
安装wsl升级包(第一步必须完成并重启)
双击exe安装
wsl --update
wsl --update --prerelease

wsl共享代理

[experimental] 
autoMemoryReclaim=gradual 
networkingMode=mirrored 
dnsTunneling=true firewall=true autoProxy=true

更新到最新的wsl prerelease后修改
Site Unreachable
wsl --manage Ubuntu --set-sparse true

docker安装

本体安装


# 更新包索引 sudo apt update# 安装依赖包 sudo apt install -y apt-transport-https ca-certificates curl software-properties-common 
# 添加 Docker 官方 GPG 密钥 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg 
# 添加 Docker 官方仓库 echo "deb [arch=$(dpkg --print-architecture) 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# 更新包索引 sudo apt update 
# 安装 Docker sudo apt install -y docker-ce docker-ce-cli containerd.io# 启动并启用 Docker 服务 sudo systemctl start docker 
sudo systemctl enable docker 
# 验证 Docker 是否安装成功 docker --version# 查看信息sudo docker info

安装完自带compose

配置WSL的system命令

sudo nano /etc/wsl.conf

添加以下内容:

[boot] systemd=true

或者使用service

换源?代理!

最新版的wsl支持mirror net,需要wsl --update 接着wsl --update --pre-release
换源无法解决拉取镜像问题

  1. 配置client代理可解决docker compose问题 没有用
    即,在WSL2中通过通用方式安装的docker.

sudo vim /etc/default/docker

输入:
export HTTP_PROXY="http://127.0.0.1:1080"
export HTTPS_PROXY="http://127.0.0.1:1080"
export NO_PROXY="localhost,127.0.0.0/8,172.16.0.0/12,192.168.0.0/16,10.0.0.0/8"

以下方法有用!

### 1、创建配置文件sudo mkdir -p /etc/systemd/system/docker.service.dsudo vim /etc/systemd/system/docker.service.d/http-proxy.conf### 2、添加配置[Service]
Environment="HTTP_PROXY=http://127.0.0.1:1080"Environment="HTTPS_PROXY=http://127.0.0.1:1080"Environment="NO_PROXY=localhost,127.0.0.1,docker-registry.example.com,.corp,"### 3、重启容器sudo systemctl daemon-reloadsudo systemctl restart docker
版权声明

本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。

评论