首页 > 解决方案 > 无法运行 Windows docker 容器中路径中的可执行文件

问题描述

我正在尝试从 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" ]

标签: windowspowershelldockerdocker-for-windows

解决方案


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

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

希望有帮助


推荐阅读