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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章