docker:连接期间出错:在Windows上的默认守护程序配置中,Docker客户端必须以提升的权限运行才能进行连接

omhiaaxx  于 2022-12-22  发布在  Docker
关注(0)|答案(6)|浏览(752)

我尝试在Windows Server 2019上以进程隔离模式运行Docker(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安装中:

作为suggested here,我尝试从本地Windows 10 Docker桌面安装中复制文件DockerCli.exe并重新运行,但随后我得到:
未处理的异常:System.IO.FileNotFoundException:未能加载文件或程序集“Docker.Core,版本= 3.0.0.50646,区域性=中性,PublicKeyToken = null”或它的某个依赖项。系统找不到指定的文件。请在Docker.Cli.MainBackendCli处运行(IReadOnlyCollection '1参数)。请在Docker.Cli.MainBackendCli.Main(String []参数)处运行(IReadOnlyCollection' 1参数)
无论如何,从Docker Desktop复制文件并不像是正确的方法。
然后我在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>
0s7z1bwu

0s7z1bwu1#

docker客户端由非管理员用户运行时,错误消息提到的管道访问是一个(可能无关的)问题(请参见here)。
我认为最可能的解释是码头服务未能启动。
当你运行dockerd时,你实际上是在 * 启动守护进程的一个示例 *--而API listen on //./pipe/docker_engine行意味着系统服务之前没有启动--因为你启动的示例可能会创建管道。
如果停止正在运行的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应显示服务正在运行,并且您的docker命令应正常。
[编辑]
看起来卸载docker失败了,因为服务不存在。然而,除了服务安装之外,安装都成功了。
您可以使用&'C:\Program Files\Docker\dockerd.exe' --register-service重新注册该服务
如果VPS提供商以某种方式停止注册服务,这可能会失败?
另一种选择是在一个shell中使用&'C:\Program Files\Docker\dockerd.exe' --run-service交互运行docker,而在另一个shell中运行docker命令。

c3frrgcw

c3frrgcw2#

为了解决这个问题,我只是在PowerShell中运行& 'C:\Program Files\Docker\Docker\DockerCli.exe' -SwitchDaemon,退出Docker桌面,并以管理员身份运行Docker桌面。
现在打开命令提示符或powershell并运行docker imagesdockers ps命令。

oyxsuwqo

oyxsuwqo3#

转到PowerShell〉以管理员身份运行并运行以下代码:

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

7z5jn7bk4#

为了解决这个问题,我只是在PowerShell中运行了两个步骤。
第一,

cd 'C:\Program Files\Docker\Docker

然后,

/DockerCli.exe' -SwitchDaemon

然后,在您的机器上安装WSL内核,重新启动WSL机器,问题就解决了。

ars1skjm

ars1skjm5#

此解决方案帮助我https://github.com/docker/for-win/issues/5919#issuecomment-658815006

cd C:\Program Files\Docker\Docker\resources dockerd.exe
Now execute
'docker version' on a new powershell as administrator
9avjhtql

9avjhtql6#

我勾选了这些选项,它对我很有效:

相关问题