windows - 无法运行 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" ]
解决方案
您需要添加一个 .\,使其看起来像 .\IarBuild.exe,因为它当前正尝试将 .exe 作为 cmdlet 处理
编辑:如果您开始输入 exe 的名称并按 Tab,如果不手动输入,它将自动完成到 .\IarBuild.exe
希望有帮助
推荐阅读
- unit-testing - Mockito 无法模拟此类(工件 BuildInfo)
- transactions - 单行事务和多行事务的区别?
- android - 更新 Android Room 中的 @PrimaryKey 值
- azure-devops - 如何在 Azure YAML 管道中将布尔值指定为变量?
- firebase - Flutter - 列表视图中的选项卡过滤
- c# - 使用套接字时,我在 beginreceive 上收到错误
- powershell - 在单独的文件中自定义 PowerShell 命令日志
- android - 如何修复清单合并失败?
- javascript - 如何使用 THREE.js 添加褪色反射?
- asp.net - Asp.net Core 3.1 HttpContext.Session.GetString("Index")