Windows10内置Linux子系统(WSL)设置服务自启

WSL 启动时运行任何服务的首选方式取决于 Windows 版本

Windows 11

/etc/wsl.conf文件添加命令

[boot]
command="service docker start"

Windows 10

在wsl linux目录的~/.bash_profile文件添加命令

 wsl.exe -u root service docker status

这里有个问题,在添加了~/.bash_profile文件后,~/.bashrc会失去效果,这是因为在添加~/.bash_profile之后,~/.profile会被覆盖不再运行。
解决方法:

  • 方案一:将~/.bash_profile中的脚本命令移至~/.profile,并删除~/.bash_profile
  • 方案二:在~/.bash_profile中添加source ~/.profile
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章