docker:连接期间出错:在 Windows 上的默认守护程序配置中,docker 客户端必须 运行 具有更高的连接权限

docker: error during connect: In the default daemon configuration on Windows, the docker client must be run with elevated privileges to connect

我正在尝试 运行 Docker Windows Server 2019 上的进程隔离模式(Docker 桌面在这里不起作用,我的 VPS不支持 Hyper-V)。 我在 PowerShell 中 运行 这个(全部在管理员模式下) docker run -it --isolation=process mcr.microsoft.com/windows/servercore:ltsc2019 cmd.exe /c ping 127.0.0.1 -t

然后我得到错误:

docker: error during connect: In the default daemon configuration on Windows, the docker client must be run with elevated privileges to connect.: Post http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.24/containers/create: open //./pipe/docker_engine: The system cannot find the file specified. See 'docker run --help'.

我 运行 命令 & 'C:\Program Files\Docker\DockerCli.exe' -SwitchDaemon,如这里所建议的:Docker cannot start on Windows

但是,DockerCli.exe 不存在于干净的 Docker 安装中:

作为 我尝试从本地 Windows 10 Docker 桌面安装复制文件 DockerCli.exe 并重新 运行,但我得到:

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'Docker.Core, Version=3.0.0.50646, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified. at Docker.Cli.MainBackendCli.Run(IReadOnlyCollection`1 args) at Docker.Cli.MainBackendCli.Main(String[] args)

无论如何,从 Docker 桌面复制文件感觉不是正确的方法。

然后我在 PowerShell 中 运行 dockerd 因为这是该文件夹中唯一的其他可执行文件:

由于我是新手,我不确定我是否刚刚启动了一个容器,如果是,我只看到了哪个容器 start.,但不知道它来自哪里或我如何才能配置它。

更新 1

根据 Peter Wishart 的建议,我尝试了 uninstall-Package -Name docker,但后来我得到了

uninstall-Package : No package found for 'docker'. At line:1 char:1
+ uninstall-Package -Name docker
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power...ninstallPackage:UninstallPackage) [Uninstall-Package]
   , Exception
    + FullyQualifiedErrorId : NoMatchFound,Microsoft.PowerShell.PackageManagement.Cmdlets.UninstallPackage

这是我尝试过的完整代码:

PS C:\Users\Administrator> uninstall-Package -Name docker
uninstall-Package : No package found for 'docker'.
At line:1 char:1
+ uninstall-Package -Name docker
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power...ninstallPackage:UninstallPackage) [Uninstall-Package]
   , Exception
    + FullyQualifiedErrorId : NoMatchFound,Microsoft.PowerShell.PackageManagement.Cmdlets.UninstallPackage

PS C:\Users\Administrator> docker

Usage:  docker [OPTIONS] COMMAND

A self-sufficient runtime for containers

Options:
      --config string      Location of client config files (default
                           "C:\Users\Administrator\.docker")
  -c, --context string     Name of the context to use to connect to the
                           daemon (overrides DOCKER_HOST env var and
                           default context set with "docker context use")
  -D, --debug              Enable debug mode
  -H, --host list          Daemon socket(s) to connect to
  -l, --log-level string   Set the logging level
                           ("debug"|"info"|"warn"|"error"|"fatal")
                           (default "info")
      --tls                Use TLS; implied by --tlsverify
      --tlscacert string   Trust certs signed only by this CA (default
                           "C:\Users\Administrator\.docker\ca.pem")
      --tlscert string     Path to TLS certificate file (default
                           "C:\Users\Administrator\.docker\cert.pem")
      --tlskey string      Path to TLS key file (default
                           "C:\Users\Administrator\.docker\key.pem")
      --tlsverify          Use TLS and verify the remote
  -v, --version            Print version information and quit

Management Commands:
  app*        Docker Application (Docker Inc., v0.8.0)
  builder     Manage builds
  cluster*    Manage Mirantis Container Cloud clusters (Mirantis Inc., v1.9.0)
  config      Manage Docker configs
  container   Manage containers
  context     Manage contexts
  image       Manage images
  manifest    Manage Docker image manifests and manifest lists
  network     Manage networks
  node        Manage Swarm nodes
  plugin      Manage plugins
  registry*   Manage Docker registries (Docker Inc., 0.1.0)
  secret      Manage Docker secrets
  service     Manage services
  stack       Manage Docker stacks
  swarm       Manage Swarm
  system      Manage Docker
  trust       Manage trust on Docker images
  volume      Manage volumes

Commands:
  attach      Attach local standard input, output, and error streams to a running container
  build       Build an image from a Dockerfile
  commit      Create a new image from a container's changes
  cp          Copy files/folders between a container and the local filesystem
  create      Create a new container
  diff        Inspect changes to files or directories on a container's filesystem
  events      Get real time events from the server
  exec        Run a command in a running container
  export      Export a container's filesystem as a tar archive
  history     Show the history of an image
  images      List images
  import      Import the contents from a tarball to create a filesystem image
  info        Display system-wide information
  inspect     Return low-level information on Docker objects
  kill        Kill one or more running containers
  load        Load an image from a tar archive or STDIN
  login       Log in to a Docker registry
  logout      Log out from a Docker registry
  logs        Fetch the logs of a container
  pause       Pause all processes within one or more containers
  port        List port mappings or a specific mapping for the container
  ps          List containers
  pull        Pull an image or a repository from a registry
  push        Push an image or a repository to a registry
  rename      Rename a container
  restart     Restart one or more containers
  rm          Remove one or more containers
  rmi         Remove one or more images
  run         Run a command in a new container
  save        Save one or more images to a tar archive (streamed to STDOUT by default)
  search      Search the Docker Hub for images
  start       Start one or more stopped containers
  stats       Display a live stream of container(s) resource usage statistics
  stop        Stop one or more running containers
  tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
  top         Display the running processes of a container
  unpause     Unpause all processes within one or more containers
  update      Update configuration of one or more containers
  version     Show the Docker version information
  wait        Block until one or more containers stop, then print their exit codes

Run 'docker COMMAND --help' for more information on a command.

To get more help with docker, check out our guides at https://docs.docker.com/go/guides/
PS C:\Users\Administrator> Get-PackageProvider -ListAvailable

Name                     Version          DynamicOptions
----                     -------          --------------
DockerMsftProvider       1.0.0.8          Update
msi                      3.0.0.0          AdditionalArguments
msu                      3.0.0.0
NuGet                    2.8.5.208        Destination, ExcludeVersion, Scope, SkipDependencies, Headers, FilterOnTag...
PowerShellGet            1.0.0.1          PackageManagementProvider, Type, Scope, AllowClobber, SkipPublisherCheck, ...
Programs                 3.0.0.0          IncludeWindowsInstaller, IncludeSystemComponent


PS C:\Users\Administrator> Get-Package -Name Docker -ProviderName DockerMsftProvider

Name                           Version          Source                           ProviderName
----                           -------          ------                           ------------
docker                         20.10.0          DockerDefault                    DockerMsftProvider


PS C:\Users\Administrator> Install-Package -Name docker -ProviderName DockerMsftProvider

The package(s) come(s) from a package source that is not marked as trusted.
Are you sure you want to install software from 'DockerDefault'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): y
PS C:\Users\Administrator> Install-Package -Name docker -ProviderName DockerMsftProvider

The package(s) come(s) from a package source that is not marked as trusted.
Are you sure you want to install software from 'DockerDefault'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): A
PS C:\Users\Administrator> uninstall-Package -Name docker
WARNING: Docker Service is not available.
uninstall-Package : The property 'Status' cannot be found on this object. Verify that the property exists.
At line:1 char:1
+ uninstall-Package -Name docker
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Microsoft.Power...ninstallPackage:UninstallPackage) [Uninstall-Package],
   Exception
    + FullyQualifiedErrorId : PropertyNotFoundStrict,Microsoft.PowerShell.PackageManagement.Cmdlets.UninstallPackage

PS C:\Users\Administrator>

docker 客户端被非管理员用户 运行 时,错误消息提到的管道访问是一个(可能无关的)问题(参见 here)。

我认为最有可能的解释是 docker 服务未能启动。

当你 运行 dockerd 你实际上是在 启动守护进程的一个实例 - API listen on //./pipe/docker_engine 行意味着系统服务之前没有启动 - 因为您启动的实例可以创建管道。

如果您停止 运行ning dockerd 实例并且 运行:

 Get-Service docker | Restart-Service
 Get-WinEvent -logname application | where ProviderName -eq docker | sort TimeCreated

您应该能够将日志输出与手动启动 dockerd 进行比较,看看是否有任何错误阻止服务启动。

如果事件日志记录 API listen on //./pipe/docker_engine,那么 Get-Service docker 应该将服务显示为 运行ning,并且您的 docker 命令应该没问题。

[编辑]

似乎卸载 docker 失败,因为该服务不存在。 然而,安装成功除了服务安装。

您可以使用 &'C:\Program Files\Docker\dockerd.exe' --register-service

重新注册服务

如果 VPS 提供商以某种方式阻止服务注册,这可能会失败?

另一种选择是 运行 docker 在一个 shell 中与 &'C:\Program Files\Docker\dockerd.exe' --run-service 交互 运行 你的 docker 命令在另一个 shell.

即使我有同样的错误,为了解决这个问题,我只是 运行 & 'C:\Program Files\Docker\Docker\DockerCli.exe' -SwitchDaemon 在 powershell 中退出 Docker 桌面和 运行 Docker 桌面作为管理员。

现在打开命令提示符或 powershell 和 运行“docker 图像”或“dockers ps”命令,它应该可以工作。

我选中了这些框,它们对我有用:

即使我有同样的错误,为了解决这个问题,我只是 运行 PowerShell 中的两个步骤。

首先,

cd 'C:\Program Files\Docker\Docker

然后,

/DockerCli.exe' -SwitchDaemon

在你的机器上安装 WSL 内核然后重启 WSL 机器然后它就解决了。

转到 PowerShell 运行 作为管理员 运行 这些代码

cd "C:\Program Files\Docker\Docker" ./DockerCli.exe -SwitchDaemon