【问题标题】:Can't run executable that is in Path in Windows docker container无法运行 Windows docker 容器中路径中的可执行文件
【发布时间】:2020-05-21 20:01:21
【问题描述】:

我正在尝试从 Power Shell 的容器内部运行可执行文件,并收到一条错误消息,提示无法找到它。但是,我已经确认它的目录在 Path 中,并且可执行文件在我期望的位置。我错过了什么?

PS C:\work\some_project> docker run -it --rm --name="iar_build" iar_env
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

PS C:\docker_work> IarBuild.exe
IarBuild.exe : The term 'IarBuild.exe' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ IarBuild.exe
+ ~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (IarBuild.exe:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS C:\docker_work> $Env:Path
C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\
OpenSSH\;C:\Users\ContainerAdministrator\AppData\Local\Microsoft\WindowsApps;C:\Program Files (x86)\IAR Systems\Embedded
 Workbench 8.1\common\bin"
PS C:\docker_work> ls 'C:\Program Files (x86)\IAR Systems\Embedded Workbench 8.1\common\bin\IarBuild.exe'


    Directory: C:\Program Files (x86)\IAR Systems\Embedded Workbench 8.1\common\bin


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----         9/1/2018   4:09 AM         724992 IarBuild.exe


PS C:\docker_work>

我的 docker 文件包含以下内容:

...
# Add the IAR common\bin\ folder to the image's PATH
RUN setx path \
  "%path%;C:\Program Files (x86)\IAR Systems\Embedded Workbench 8.1\common\bin\"
...
CMD [ "powershell.exe", "-executionpolicy" , "Unrestricted" ]

【问题讨论】:

  • SETX 将变量写入注册表HKCU\Environment 中的主环境,并且不影响当前的 CMD 或 PowerShell 会话(来自setx /? 的信息)。请注意,我不知道 docker 的 RUN setx path …$Env:Path 和后续 ls 的输出似乎有点令人困惑,因为 $Env:Path 中的尾随双引号?
  • 如果我使用 cmd 而不是 powershell,例如CMD [ "cmd" ]我可以调用 IarBuild.exe
  • PowerShell 中的where.exe IarBuild.exe 怎么样?
  • PS C:\docker_work> where.exe IarBuild.exe INFO: Could not find files for the given pattern(s).
  • $Env:Path 中的尾随双引号是错字吗?

标签: windows powershell docker docker-for-windows


【解决方案1】:

您需要添加一个 .\,使其看起来像 .\IarBuild.exe,因为它当前正尝试将 .exe 作为 cmdlet 进行处理

编辑:如果您开始输入 exe 的名称并按 Tab,如果不手动输入,它将自动完成到 .\IarBuild.exe

希望有帮助

【讨论】:

  • .\IarBuild.exe 具有相同的结果。选项卡自动完成没有找到它。
  • 对不起,我刚刚阅读了您的所有代码,因为 .\IarBuild.exe 不在根文件夹 Docker_Work 中,它不会找到它,您需要使用 Start-Process "C:\Program Files (x86 )\IAR Systems\Embedded Workbench 8.1\common\bin\IarBuild.exe"
  • Powershell 可以从Path 的目录中找到其他实用程序,那么为什么不是这个呢?此外,这与我在主机系统上所期望的完全一样。它只是在容器中不起作用。
猜你喜欢
  • 2020-02-11
  • 2020-06-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-08-10
  • 1970-01-01
  • 2016-02-29
相关资源
最近更新 更多