基于WSL2 的 Docker Desktop 启动时 Failed to set version to docker-desktop: exit code: -1的解决方法

在Windows 10 的 2004 版本  中, 启用 使用Docker Desktop 时 发现  根本无法启动, 偶尔或者频繁的出错:

System.InvalidOperationException:Failed to set version to docker-desktop: exit code: -1 
System.InvalidOperationException:Failed to set version to docker-desktop: exit code: -1  stderr:    在 Docker.ApiServices.WSL2.WslShortLivedCommandResult.LogAndThrowIfUnexpectedExitCode(String prefix, ILogger log, Int32 expectedExitCode) 位置 C:\workspaces\PR-15077\src\github.com\docker\pinata\win\src\Docker.ApiServices\WSL2\WslCommand.cs:行号 146   在 Docker.Engines.WSL2.WSL2Provisioning.<ProvisionAsync>d__8.MoveNext() 位置 C:\workspaces\PR-15077\src\github.com\docker\pinata\win\src\Docker.Desktop\Engines\WSL2\WSL2Provisioning.cs:行号 82--- 引发异常的上一位置中堆栈跟踪的末尾 ---   在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()   在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)   在 Docker.Engines.WSL2.LinuxWSL2Engine.<DoStartAsync>d__25.MoveNext() 位置 C:\workspaces\PR-15077\src\github.com\docker\pinata\win\src\Docker.Desktop\Engines\WSL2\LinuxWSL2Engine.cs:行号 99--- 引发异常的上一位置中堆栈跟踪的末尾 ---   在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()   在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)   在 Docker.ApiServices.StateMachines.TaskExtensions.<WrapAsyncInCancellationException>d__0.MoveNext() 位置 C:\workspaces\PR-15077\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-15077\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-15077\src\github.com\docker\pinata\win\src\Docker.ApiServices\StateMachines\StartTransition.cs:行号 92

启动 WSL 2时警告“参考的对象类型不支持尝试的操作”

管理员方式执行cmd命令

netsh winsock reset

然后启动  docker-desktop

转载csdn博文:

https://blog.csdn.net/MShow006/article/details/103774672

https://blog.csdn.net/mysticboy/article/details/106632922