Docker が wsl で自動的に起動します

序文

wsl -l -v#wslステータスを確認する
wsl -t Ubuntu# 指定したバージョンを閉じる
wsl -d Ubuntu# 指定したバージョンを起動する

起動するdocker

コマンドを通じて、ps -p 1 -o comm=それを使用していることがわかるのでinit、systemd コマンドを SysV init コマンドに変更します。

ps -p 1 -o comm=
ここに画像の説明を挿入します

コマンドを置き換えて、systemd の代わりに SysV init コマンドを使用します。

$ sudo service docker start
$ service docker status

セルフスタートdocker

WSL2内での操作

sudo vim /etc/init.wsl
#! /bin/sh
service docker start
sudo chmod +x /etc/init.wsl

Windows内での操作

  1. Windows システムで起動スクリプトを作成しますstartup.vbs
Set ws = WScript.CreateObject("WScript.Shell")        
ws.run "wsl -d ubuntu -u root /etc/init.wsl"

注: 「ubuntu」は WSL2 サブシステムの名前です。

  1. win+Rを押してshell:startupと入力し、上記のvbsファイルをこのディレクトリに置きます。

説明する

多くのチュートリアルでは sudo systemctl enable docker と sudo systemctl start docker を使用するように記載されていますが、実際にはエラーが報告されます。

Windows 10 の WSL で Ubuntu20.04 を使用しています。コマンドを使用すると、次のsudo systemctl status dockerエラーが発生します。

System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down

問題の原因:
一般的な Linux オペレーティング システムの場合、Linux では systemd が使用されていないため、Linux 上のサービスを管理するために systemd コマンドを使用したいため、エラーが報告される可能性があります。古典的な SysV init (sysvinit) システムが使用されます。
ただし、私のものはWindows 10でWSLを備えたUbuntuであるため、systemdの代わりにSysV initを使用します。

解決策:
コマンドを置き換えて、systemd の代わりに SysV init コマンドを使用します。

画像.png

参照

@article{glc4002021Sep、
著者 = {glc400}、
タイトル = { {{WSL システム systemctl が使用できない問題の解決策}}、
ジャーナル = {SegmentFault Sifu}、
年 = {2021}、
月 = 9 月、
urldate = {2023-06 - 20}、
発行者 = {SegmentFault}、
言語 = {中国語}、
URL = {https://segmentfault.com/a/1190000040670856}
}
@misc{BibEntry2023Jun、
title = { {Windows 11 の Linux サブシステムに Docker をインストールする}} 、
日記 = {志湖コラム}、
年 = {2023}、
月 = 6 月、
urldate = {2023-06-20}、
言語 = {中国語}、
メモ = {[オンライン; 2023 年 6 月 20 日にアクセス]} 、
url = {https://zhuanlan.zhihu.com/p/433898505}
}
@misc{BibEntry2023May,
title = { {wsl2 構成サービスの自動開始{\textendash} 故郷への帰還を夢見て}}、
年 = {2023}、
月 = 5 月、
urldate = {2023-06-20}、
言語 = {中国語}、
note = {[オンライン ; 2023 年 6 月 20 日にアクセス]}、
url = {https://www.80shihua.com/archives/2890}
}

おすすめ

転載: blog.csdn.net/orDream/article/details/131311175