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
。