LoginSignup
22
24

More than 1 year has passed since last update.

Windows docker起動エラー(WSL2 利用)

Last updated at Posted at 2021-06-03

WindowsのDockerか起動エラー(コンテナ起動前)が発生した場合に さまざまなケースがあり、この対応で解決できる という情報にたどりつけない。
そこで、見直す、参考にする事項をいくつかあげています。

かれこれ、WindowsでDocker起動できないのは 3回ありました。
Mac数年使っていて Docker for Macで docker が起動できない事象に遭遇したことはないです。

この記事書いたときの バージョン

PS > systeminfo

OS 名:                  Microsoft Windows 10 Pro
OS バージョン:          10.0.19042 N/A ビルド 19042
OS 製造元:              Microsoft Corporation
システムの種類:         x64-based PC
プロセッサ:             1 プロセッサインストール済みです。
                        [01]: Intel64 Family 6 Model 165 Stepping 5 GenuineIntel ~2901 Mhz
BIOS バージョン:        American Megatrends Inc. M.008, 2020/06/24

Hyper-V の要件:         ハイパーバイザーが検出されました。Hyper-V に必要な機能は表示されません。
ソフト バージョンやサイズ
Docker Desktop Installer.exe v3.3.3
wsl_update_x64.msi 作成日時 ‎2021‎年‎3‎月‎3‎日、‏‎14:46:58、サイズ 14.5 MB (15,282,176 バイト)
NoLsp.exe サイズ 1.43 MB (1,501,104 バイト)、WSL2とdockerならば使わなくても良い、WSL2 ubuntuの場合に使う

ログ・ファイル、エラーログ

  • ログファイルの場所
    C:\Users\your-account\AppData\Local\Docker , %USERPROFILE%\AppData\Local\Docker

    • log.txt 最新のログファイル
    • log.66.txt, log.67.txt, log.68.txt のようにローテーションされるため対応前後のファイルが必要になることがあるのでファイルをどこにかにコピーしておく
  • ログエラーのサンプル

あくまでも一例です

[13:15:31.034][LoggingMessageHandler][Info   ] [a61e2e22] <BackendAPIClient start> POST http://backend/dns/refresh-hosts
[13:15:31.250][WSL2Provisioning  ][Info   ] Checking docker-desktop
[13:15:31.254][LoggingMessageHandler][Info   ] [a61e2e22] <BackendAPIClient end> POST http://backend/dns/refresh-hosts -> 204 NoContent (took 219ms)
[13:15:31.310][WSL2Provisioning  ][Info   ] deploying WSL distro docker-desktop to C:\Users\your-account\AppData\Local\Docker\wsl\distro
[13:15:31.446][WSL2Provisioning  ][Error  ] Failed to deploy distro docker-desktop to C:\Users\your-account\AppData\Local\Docker\wsl\distro: exit code: -1
 stdout: c?[U0?0_0?0?0L0??d0K0?0~0[0?00


 stderr: 
[13:15:31.449][LinuxWSL2Engine   ][Info   ] Stopping windows side processes
[13:15:31.492][LinuxWSL2Engine   ][Info   ] Stopping engine
[13:15:31.524][LoggingMessageHandler][Info   ] [1dfcf536] <BackendAPIClient start> POST http://backend/windowsfeatures/check
[13:15:31.863][CliInstaller      ][Info   ] Reading build information from appcast
[13:15:31.912][LoggingMessageHandler][Info   ] [1dfcf536] <BackendAPIClient end> POST http://backend/windowsfeatures/check -> 200 OK (took 387ms)
[13:15:31.962][Updater           ][Debug  ] Finished check for updates
[13:15:32.146][LinuxWSL2Engine   ][Info   ] Terminating lingering processes and wsl distros and patching host file
[13:15:32.146][LoggingMessageHandler][Info   ] [a6104593] <BackendAPIClient start> POST http://backend/dns/refresh-hosts
[13:15:32.162][LoggingMessageHandler][Info   ] [a6104593] <BackendAPIClient end> POST http://backend/dns/refresh-hosts -> 204 NoContent (took 16ms)
[13:15:32.197][WSL2Provisioning  ][Info   ] Checking docker-desktop
[13:15:32.197][WSL2Provisioning  ][Info   ] deploying WSL distro docker-desktop to C:\Users\your-account\AppData\Local\Docker\wsl\distro
[13:15:32.330][WSL2Provisioning  ][Error  ] Failed to deploy distro docker-desktop to C:\Users\your-account\AppData\Local\Docker\wsl\distro: exit code: -1
 stdout: c?[U0?0_0?0?0L0??d0K0?0~0[0?00


 stderr: 
[13:15:32.330][LinuxWSL2Engine   ][Info   ] Stopping windows side processes
[13:15:32.364][LinuxWSL2Engine   ][Info   ] Stopping engine
[13:15:32.387][EngineStateMachine][Debug  ] sending state Docker.ApiServices.StateMachines.FailedToStartState to state change sink
[13:15:32.387][EngineStateMachine][Debug  ] State Docker.ApiServices.StateMachines.FailedToStartState sent to state change sink
[13:15:32.387][EngineStateListener][Debug  ] received state Docker.ApiServices.StateMachines.FailedToStartState from LinuxWSL2
[13:15:32.388][EngineStateNotificationRecorder][Debug  ] Registered state {"State":"failed to start","Mode":"linux","date":1622693732}
[13:15:32.463][SystrayNotifications][Error  ] System.InvalidOperationException: Failed to deploy distro docker-desktop to C:\Users\your-account\AppData\Local\Docker\wsl\distro: exit code: -1
 stdout: c?[U0?0_0?0?0L0??d0K0?0~0[0?00


 stderr: 
   場所 Docker.ApiServices.WSL2.WslShortLivedCommandResult.LogAndThrowIfUnexpectedExitCode(String prefix, ILogger log, Int32 expectedExitCode) 場所 C:\workspaces\PR-15766\src\github.com\docker\pinata\win\src\Docker.ApiServices\WSL2\WslCommand.cs:行 146
   場所 Docker.Engines.WSL2.WSL2Provisioning.<DeployDistroAsync>d__17.MoveNext() 場所 C:\workspaces\PR-15766\src\github.com\docker\pinata\win\src\Docker.Desktop\Engines\WSL2\WSL2Provisioning.cs:行 169
--- 直前に例外がスローされた場所からのスタック トレースの終わり ---
   場所 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   場所 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   場所 Docker.Engines.WSL2.WSL2Provisioning.<ProvisionAsync>d__8.MoveNext() 場所 C:\workspaces\PR-15766\src\github.com\docker\pinata\win\src\Docker.Desktop\Engines\WSL2\WSL2Provisioning.cs:行 78
--- 直前に例外がスローされた場所からのスタック トレースの終わり ---
   場所 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   場所 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   場所 Docker.Engines.WSL2.LinuxWSL2Engine.<DoStartAsync>d__26.MoveNext() 場所 C:\workspaces\PR-15766\src\github.com\docker\pinata\win\src\Docker.Desktop\Engines\WSL2\LinuxWSL2Engine.cs:行 102
--- 直前に例外がスローされた場所からのスタック トレースの終わり ---
   場所 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   場所 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   場所 Docker.ApiServices.StateMachines.TaskExtensions.<WrapAsyncInCancellationException>d__0.MoveNext() 場所 C:\workspaces\PR-15766\src\github.com\docker\pinata\win\src\Docker.ApiServices\StateMachines\TaskExtensions.cs:行 29
--- 直前に例外がスローされた場所からのスタック トレースの終わり ---
   場所 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   場所 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   場所 Docker.ApiServices.StateMachines.StartTransition.<DoRunAsync>d__5.MoveNext() 場所 C:\workspaces\PR-15766\src\github.com\docker\pinata\win\src\Docker.ApiServices\StateMachines\StartTransition.cs:行 67
--- 直前に例外がスローされた場所からのスタック トレースの終わり ---
   場所 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   場所 Docker.ApiServices.StateMachines.StartTransition.<DoRunAsync>d__5.MoveNext() 場所 C:\workspaces\PR-15766\src\github.com\docker\pinata\win\src\Docker.ApiServices\StateMachines\StartTransition.cs:行 92
[13:15:32.473][GUI               ][Info   ] Sending Bugsnag report 35ebbca3-b758-46f6-9b0f-2dd97c5f903d...
[13:15:33.020][GUI               ][Info   ] Bugsnag report 35ebbca3-b758-46f6-9b0f-2dd97c5f903d sent
[13:15:33.021][SegmentApi        ][Info   ] Usage statistic: eventCrash
[13:15:33.023][Diagnostics       ][Warning] Starting to gather diagnostics as User : 'C:\Program Files\Docker\Docker\resources\com.docker.diagnose.exe' gather.
[13:15:33.161][Engines           ][Error  ] Start failed with Failed to deploy distro docker-desktop to C:\Users\your-account\AppData\Local\Docker\wsl\distro: exit code: -1
 stdout: c?[U0?0_0?0?0L0??d0K0?0~0[0?00

見直すべき事項

dockerアンインストールでの注意点

  • dockerをアンインストールすると、コンテナのファイル C:\Users\your-account\AppData\Local\Docker\wsl( %USERPROFILE%\AppData\Local\Docker ) の中のフォルダのファイルを消してしまうので、必要ならばバックアップしておく。data\ext4.vhdx では 10GBくらいは普通にありえる。

WSL2とDocker Desktopを入れ直す

  • dockerを入れ直しても解決しないことが多々あります
  • dockerインストールでは、インストール時にWSL2の必須コンポーネントを同時に入れるケースと、そのオプションをチェックoffにしてインストールするケースがあります
  • WSL2を使えるようにする、コントロールパネル→プログラムと機能→ にある「Windowsの機能を有効化または無効化」でも、幾度かやっても解決できないことがあります

調査するときの参考サイトと説明

WSL2をアンインストールしてMS公式のWindows10にインストールして、ubuntuのコンテナを使う例です

アンインストール・削除

  • PC設定 -> アプリ -> アプリと機能 -> 「このリストを検索」で ubuntu 入力して、ubuntuが見つかったら「アンインストール」を行う

  • Docker Desktop:Docker Desktop Installer.exeで入れたもの
    コントロール パネル\すべてのコントロール パネル項目\プログラムと機能 にてアンインストール

  • Windows Subsystem for Linux Update :wsl_update_x64.msiで入れたもの
    コントロール パネル\すべてのコントロール パネル項目\プログラムと機能にてアンインストール

  • コントロール パネル\すべてのコントロール パネル項目\プログラムと機能のWindowsの機能の有効化または無効化にて、

    • Hype-V :チェックoff
    • Linux用Windows サブシステム(表記違う可能性あり):チェックoff
    • 仮想マシンプラットフォーム:チェックoff

参考の画面(チェックONなので、offにする必要がある)
windowsの機能.png

  • 上記のチェックoffで進めて、OS再起動します

インストール

  • その後に入れ直しとして、MS公式手順で進める。
    MS公式は、管理者で PowerShell を開いてコマンド入力しています、そのコマンドはGUI画面でのWindowsの機能の有効化または無効化で、チェックON(有効にする)の代わりをコマンドで行っています。
    再起動タイミングを間違えないこと

  • MS公式手順での 手順 6 - 選択した Linux ディストリビューションをインストールする は、インストールできても、起動でエラー0x80070003 が出たら、MSストアから入れるのを諦める、または、https://github.com/microsoft/WSL/issues/3232 を参考にしてみる

ワークアラウンド

対応例1)

WSL2を入れるまではMS公式手順とほぼ同じで、その後の docker desktopインストールでのWSL2オプションをチェックoffにして入れる

対応例2)

WSL2 backend always crash System.InvalidOperationException: Failed to deploy distro docker-desktop #7208 https://github.com/docker/for-win/issues/7208 にある、https://github.com/docker/for-win/issues/7208#issuecomment-643697540 の対応で動くこともあります

対応例3)

https://github.com/docker/for-win/issues/8204の https://github.com/docker/for-win/issues/8204#issuecomment-683377496 の対応

ワークアラウンドの手順(「仮想マシンプラットフォーム」は無効化と有効化はしていない。docker起動エラーのワークアラウンドのため、おそらく有効化の前提かと思われる)

As a workaround to get Docker working on a Windows Insider build.

Uninstall Docker and WSL 2 kernel.
Go to the Control Panel -> Programs -> Turn Windows features on or off
Uncheck the following: Containers, Hyper-V, Windows Subsystem for Linux
Restart the system
Install Docker without the WSL2 enabled/checked in the first screen
Go to the Control Panel -> Programs -> Turn Windows features on or off
Turn on/check the Windows Subsystem for Linux
Restart the system.
Do not install the WSL2 Kernel.

docker-desktopのインストールの最初で、Install required Windows components for WSL 2 のチェックoff(の日本語相当忘れてしまったけど、)にしてインストールする

このケースの場合の他の対応例
https://stackoverflow.com/questions/66026771/my-docker-is-failing-to-launch-on-my-windows-10-pro

対応例4)For information on key differences with WSL 2 please...

PS> wsl --set-default-version 2

For information on key differences with WSL 2 please visit https://aka.ms/wsl2

WSL2をデフォルトに設定するコマンドで上記のようになる(Error にはならない)
ひとまず、そのまま使う

対応例5)wslコマンドがおかしい、マイクロストアからダウンロードした WSL2 ubuntu が起動でおかしい

  • wsl_update_x64.msi インストール前
>wsl
WSL 2 を実行するには、カーネル コンポーネントの更新が必要です。詳細については https://aka.ms/wsl2kernel を参照してください
  • wsl_update_x64.msi インストールすると、メッセージが変わる
>wsl
実行しようとした操作は、参照したオブジェクトの種類ではサポートされていません。

ただ、wsl_update_x64.msiをインストールしただけでは動かない

上記2つのURLをもとに、

↑をダウンロードしてきて c:\app\NoLsp.exe に置いたとして powershellを管理者として実行して、exeを実行する。実行には「.\」が必要。

  • NoLsp.exeの実行例
PS C:\app> .\NoLsp.exe c:\windows\system32\wsl.exe
Success!

その後に、cmdコマンドプロンプト wsl コマンドを実行すると、

Users\test>wsl
Welcome to Ubuntu 20.04.2 LTS (GNU/Linux 5.4.72-microsoft-standard-WSL2 x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Wed Mar  3 15:19:59 JST 2021

  System load:  0.0                Processes:             8
  Usage of /:   0.4% of 250.98GB   Users logged in:       0
  Memory usage: 0%                 IPv4 address for eth0: 192.168.144.93
  Swap usage:   0%

1 update can be installed immediately.
0 of these updates are security updates.
To see these additional updates run: apt list --upgradable


The list of available updates is more than a week old.
To check for new updates run: sudo apt update


This message is shown once a day. To disable it please create the
/root/.hushlogin file.

これで、wsl -l -v や wsl2のubuntuが正常に使える

その他

WSL2では、Hyper-V とは共存しない

https://github.com/docker/for-win/issues/6640#issuecomment-687304908
の通り、WSL2使うならば、Hyper-V はチェックoff であること

ubuntuをMSストアから入れず、docker desktopだけインストールされている状態のwslでは

WSL2とdockerが紐づけられている

PS > wsl -l -v
  NAME                   STATE           VERSION
* docker-desktop-data    Running         2
  docker-desktop         Running         2

22
24
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
22
24