Skip to content

windows开发环境构建:wls2、docker、git、ssr

Notifications You must be signed in to change notification settings

lianzhanbiao/wsl2-development

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 

Repository files navigation

一、安装WSL2

参照 https://docs.microsoft.com/en-us/windows/wsl/install-win10

二、安装docker desktop windows

参照 https://docs.docker.com/docker-for-windows/install/

三、docker在wsl2下的设置

参照 https://docs.docker.com/docker-for-windows/wsl/

四、WSL2科学上网

对应的软件设置为允许局域网连接(我使用的是SSR)

alt

防火墙设置放行

alt

在wsl2 terminal中打开vim ~/.bashrc(vscode中打开为 code ~/.bashrc),在最下边添加如下代码

# set http proxy
WSL_MASTER_HOST_IP=`cat /etc/resolv.conf | grep nameserver | awk '{print $2}'`

export http_proxy="http://${WSL_MASTER_HOST_IP}:1080"  # 此处端口对应SSR的本地端口1080

export https_proxy=$http_proxy

export all_proxy=$http_proxy

# set git config http proxy

if [ "`git config --global --get http.proxy`" != "http://$WSL_MASTER_HOST_IP:1080" ]; then

  git config --global http.proxy http://$WSL_MASTER_HOST_IP:1080

fi

如果是使用zsh则是打开 vim ~/.zshrc(或者code ~/.zshrc),添加上边的代码到末尾

wsl2 ping 不通主机时,需要设置 wsl2 网络允许通过防火墙(需要管理员权限打开cmd/powershell执行)

# cd folder
cd C:\WINDOWS\system32

# run
New-NetFirewallRule -DisplayName "WSL" -Direction Inbound  -InterfaceAlias "vEthernet (WSL)"  -Action Allow

测试连接(wsl 环境下)

# 查看 wsl 的ip
env
# 找到环境变量 http_proxy ,查看主机 ip,假设为 window_ip
ping window_ip

五 Git相关设置

设置wsl ssh共享请参考https://devblogs.microsoft.com/commandline/sharing-ssh-keys-between-windows-and-wsl-2/

设置github代理,使用http:// 协议代替 git://
打开 vim ~/.gitconfig,将下边代码添加至末尾

[url "https://github.com/"]
  insteadOf = git://github.com/

设置多个ssh连接参照 https://linuxize.com/post/using-the-ssh-config-file/
例如本地配置github、gitee的ssh ~/.ssh/config

Host github.com
  User git
  Port 22
  Hostname github.com
  # 注意修改路径为你的路径
  IdentityFile "~/.ssh/id_rsa"
  TCPKeepAlive yes

Host ssh.github.com
  User git
  Port 443
  Hostname ssh.github.com
  # 注意修改路径为你的路径
  IdentityFile "~/.ssh/id_rsa"
  TCPKeepAlive yes

Host gitee.com
  User git
  Port 22
  Hostname gitee.com
  # 注意修改路径为你的路径
  IdentityFile "~/.ssh/id_rsa"
  TCPKeepAlive yes

Host ssh.gitee.com
  User git
  Port 443
  Hostname ssh.gitee.com
  # 注意修改路径为你的路径
  IdentityFile "~/.ssh/id_rsa"
  TCPKeepAlive yes

六、docker项目中文件权限

运行docker ps(或相关docker指令)有权限问题时需要修复docker权限

sudo addgroup --system docker
sudo adduser $USER docker
newgrp docker

项目文件权限问题,在wsl2下设置文件夹权限为777即可

# 例如我的工作目录为 ~/workspace
cd ~/
sudo chmod -R 777 workspace/

注意事项

启动ssr或者相关软件时请关闭windows下其他代理(检查windows代理端口是否正确),防止冲突导致ssr不生效

About

windows开发环境构建:wls2、docker、git、ssr

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published