命令"docker"Windows Powershell中无法识别 [英] Command "docker" not recognized in windows powershell

查看:181
本文介绍了命令"docker"Windows Powershell中无法识别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Windows Powershell(在Windows 10上).我也在使用最新版本的Docker桌面2.3.0.5.当我输入"docker version"时,在PowerShell中,无法识别该命令.错误消息显示为"Der angegebenen Datei ist keine Anwendung zugeordnet".(英语:未将应用程序分配给指定的文件).当我改为包含文件扩展名并键入"docker.exe version"时,该命令可以执行.有趣的是,"docker版本"在cmd窗口中工作,但由于某种原因不在powershell中工作.扩展名".exe"包含在Windows环境变量PATHEXT中.

I am using Windows Powershell (on windows 10). I am also using the latest version 2.3.0.5 of docker desktop. When I type "docker version" in powershell the command is not recognized. The error message reads "Der angegebenen Datei ist keine Anwendung zugeordnet." (English: No application is assigned to the specified file). When I instead include the file extension and type "docker.exe version" the command can be executed. The interesting thing is that "docker version" works in a cmd window, but for some reason not in powershell. The extension ".exe" is contained in the windows environment variable PATHEXT.

在Powershell中不起作用的原因可能是什么?

What could be the reason that it doesn't work in powershell?

PS:我之前安装了旧版本的docker.那里一切正常.然后,我更新到了最新版本.之后,我将无法再使用现有的Docker容器.因此,我卸载了旧版本并安装了2.3.0.5版.从那以后我遇到了这个问题.

PS: I had an old version of docker installed before. There everything worked fine. Then I updated to the newest version. After that I couldn't use my existing docker containers anymore. So I uninstalled the old version and installed version 2.3.0.5. Since then I have this issue.

推荐答案

tl; dr:

  • 运行 Get-Command-所有docker |ForEach-Object路径

在返回的文件路径中,删除不以 *.exe 结尾的文件路径(使用 Remove-Item ).

Among the file paths returned, remove those that do not end in *.exe (use Remove-Item).

最可能的解释是,在系统路径中的一个目录( $ env:PATH )中,之前> docker.exe 所在,包含另一个文件,其基本名称 docker :

The likeliest explanation is that, in one of the directories in your system's path ($env:PATH) that comes before the one in which docker.exe is located, contains another file whose base name is docker:

  • 任何一个:它是无扩展名的文件,其字面全称是 docker [em>这就是问题所在所在的地方].

  • Either: It is an extension-less file literally and fully named docker [This is what it the problem turned out to be] .

  • PowerShell意外地尝试执行此无扩展名的文件,因为它认为它是可执行的,尽管-根据定义,它没有通过 PATHEXT 环境变量(> $ env:PATHEXT ). [1]

  • 这将解释 cmd.exe 的不同行为,因为它明智地从不考虑无扩展名的文件可执行文件.
  • This would explain cmd.exe's different behavior, because it sensibly never considers an extension-less file executable.

大概是,旧版Docker的卸载删除了原始的 docker.exe ,但在该目录后面的同一目录中保留了一个无扩展名的 docker 文件(可能是 Unix shell脚本).

Presumably, the uninstallation of the old Docker version removed the original docker.exe, but left an extension-less docker file in the same directory behind (possibly a Unix shell script).

:确实具有扩展名( *.exe 除外),

Or: It does have an extension (other than *.exe), which:

  • 是指不是直接 可执行文件的文件,需要一个解释器-一个单独的可执行文件-才能执行

  • refers to a file that isn't directly executable and needs an interpreter - a separate executable - in order to be executed

该扩展名在 PATHEXT 环境变量中列出

and that extension is listed in the PATHEXT environment variable

文件扩展名(例如 .py )与关联解释器(有关该信息的信息)之间的关联(现在)丢失了,可能是因为是因为卸载了旧版Docker.

and the association between the filename extension (e.g., .py) and the (information about the) associated interpreter is (now) missing, possibly as a result of having uninstalled the older Docker version.

[1]实际上, PowerShell意外地认为任何文件扩展名可执行文件-请参见

[1] In fact, PowerShell unexpectedly considers any filename extension executable - see GitHub issue #12632.
However, for those extensions not listed in PATHEXT, execution via the path only works if you include the filename extension in a file-name-only call (e.g., executing file.txt opens a file by that name located in the first folder in the path that has such a file in the associated editor). With an extension-less file, there is obviously no extension to include, which is why confusion with an *.exe file of the same base name is possible (unless you invoke with .exe); if both such files reside in the same directory in the path, the *.exe file takes precedence, but if the extension-less file is in a different directory listed earlier in the path, it takes precedence.

这篇关于命令"docker"Windows Powershell中无法识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆