shell脚本解决Win10 WSL2 IP地址经常变动导致docker容器无法正常访问
📺

shell脚本解决Win10 WSL2 IP地址经常变动导致docker容器无法正常访问

Tags
Property
Ubuntu 20.04 wls2
cd ~
vim ./bashrc
#复制到./bashrc
hostname="wslhost"

wslip=$(ip address show eth0 | grep 'inet ' | awk '{print $2}' | awk -F/ '{print $1}')

cp /mnt/c/Windows/System32/drivers/etc/hosts /tmp
sed -i "/$hostname/d" /tmp/hosts
echo "$wslip $hostname" >> /tmp/hosts
cp /tmp/hosts /mnt/c/Windows/System32/drivers/etc/hosts
source ~/.bashrc # 使更新,立即生效
会修改Windows hosts文件(位置:C:\Windows\System32\drivers\etc\hosts),效果如下:
notion image
1.配置xshell shh登录
ssh://wslhost:22
notion image
2.配置docker
notion image
notion image
2.查看docker容器和镜像
notion image
 

Loading Comments...