[英]Error running while executing "docker exec" on running containers
I have been trying to execute below commands on my running container but every time I execute any command it gives me an error.我一直试图在我正在运行的容器上执行以下命令,但每次执行任何命令时,它都会给我一个错误。 The image is for windows containers
该图像适用于 Windows 容器
docker exec "Container name" cat /etc/hosts
docker exec "Container name" bash
docker exec "Container name" sh
this is the error I get这是我得到的错误
container 765e4e8d647d54051c1926e591666b87d1e6e95187920f9e42f6b62b97ff508e encountered an error during hcsshim::System::CreateProcess: failure in a Windows system call: The system cannot find the file specified. (0x2)
[Event Detail: Provider: 00000000-0000-0000-0000-000000000000]
[Event Detail: Provider: 00000000-0000-0000-0000-000000000000]
[Event Detail: onecore\vm\compute\management\orchestration\vmhostedcontainer\processmanagement.cpp(173)\vmcomputeagent.exe!00007FF6B747AE77: (caller: 00007FF6B742E4AB) Exception(3) tid(798) 80070002 The system cannot find the file specified.
CallContext:[\Bridge_ProcessMessage\VmHostedContainer_ExecuteProcess]
Provider: 00000000-0000-0000-0000-000000000000] extra info: {"CommandLine":"cat /etc/host","WorkingDirectory":"/","Environment":{"COMPLUS_NGenProtectedProcess_FeatureEnabled":"0","DOTNET_RUNNING_IN_CONTAINER":"true","ROSLYN_COMPILER_LOCATION":"c:\\RoslynCompilers\\tools"},"CreateStdInPipe":true,"CreateStdOutPipe":true,"CreateStdErrPipe":true,"ConsoleSize":[0,0]}
PS C:\windows\system32> docker exec angry_pascal cat /etc/host
container 765e4e8d647d54051c1926e591666b87d1e6e95187920f9e42f6b62b97ff508e encountered an error during hcsshim::System::CreateProcess: failure in a Windows system call: The system cannot find the file specified. (0x2)
[Event Detail: Provider: 00000000-0000-0000-0000-000000000000]
[Event Detail: Provider: 00000000-0000-0000-0000-000000000000]
[Event Detail: onecore\vm\compute\management\orchestration\vmhostedcontainer\processmanagement.cpp(173)\vmcomputeagent.exe!00007FF6B747AE77: (caller: 00007FF6B742E4AB) Exception(4) tid(638) 80070002 The system cannot find the file specified.
CallContext:[\Bridge_ProcessMessage\VmHostedContainer_ExecuteProcess]
Provider: 00000000-0000-0000-0000-000000000000] extra info: {"CommandLine":"cat /etc/host","WorkingDirectory":"/","Environment":{"COMPLUS_NGenProtectedProcess_FeatureEnabled":"0","DOTNET_RUNNING_IN_CONTAINER":"true","ROSLYN_COMPILER_LOCATION":"c:\\RoslynCompilers\\tools"},"CreateStdInPipe":true,"CreateStdOutPipe":true,"CreateStdErrPipe":true,"ConsoleSize":[0,0]}
I went through docker documentation and some Github forums as well but I couldn't find a solution to it.我也浏览了docker 文档和一些 Github 论坛,但找不到解决方案。 Below is my docker file
下面是我的 docker 文件
FROM microsoft/aspnet
COPY ./bin/Release/PublishOutput .
Its a very basic docker file, so I am not sure if I am missing something or I am doing something wrong.它是一个非常基本的 docker 文件,所以我不确定我是否遗漏了什么或者我做错了什么。 Any help on this would be appreciated.
对此的任何帮助将不胜感激。 Cheers!
干杯!
I'm pretty sure /etc/host
file won't be inside container because you're missing last s
.我很确定
/etc/host
文件不会在容器内,因为您缺少最后一个s
。
Also I don't know much about Windows containers but my wild guess would be that linux binaries such as sh
, bash
or cat
are not available in Windows.此外,我对 Windows 容器知之甚少,但我的猜测是
sh
、 bash
或cat
等 linux 二进制文件在 Windows 中不可用。 Instead you should invoke powershell.exe
for example as described here:相反,您应该调用
powershell.exe
例如,如下所述:
https://www.ntweekly.com/2019/09/20/how-to-attach-to-a-running-windows-container/ https://www.ntweekly.com/2019/09/20/how-to-attach-to-a-running-windows-container/
As mentioned by @Ordrej Bardon that I wasn't using windows commands to interact with my container and instead of using sh
, bash
or cat
I should use powershell.exe
or cmd.exe
.正如@Ordrej Bardon 所提到的,我没有使用 Windows 命令与我的容器交互,我应该使用
powershell.exe
或cmd.exe
而不是使用sh
、 bash
或cat
。 This would solve one part of the problem but would start giving这将解决问题的一部分,但会开始给予
service 'w3svc' failed
APPCMD failed with error code 4312
Failed to update IIS configuration
To solve this problem refer to Can't run microsoft/aspnet interactively .要解决此问题,请参阅无法以交互方式运行 microsoft/aspnet 。 Here the solution and explanation of this problem is given
这里给出了这个问题的解决方案和解释
Solution : Changes in Dockerfile解决方案:Dockerfile 中的更改
Add ENTRYPOINT["powershell"]
添加
ENTRYPOINT["powershell"]
FROM microsoft/aspnet
ENTRYPOINT["powershell"]
COPY ./bin/Release/PublishOutput .
Explanation:解释:
The entrypoint is defined as ENTRYPOINT ["C:\\ServiceMonitor.exe", "w3svc"].
入口点定义为 ENTRYPOINT ["C:\\ServiceMonitor.exe", "w3svc"]。 When you add cmd.exe as the run parameter, it is attempting to add that as an argument after ServiceMonitor.exe w3svc.
当您将 cmd.exe 添加为运行参数时,它会尝试将其添加为 ServiceMonitor.exe w3svc 之后的参数。 With that Dockerfile, you could then do docker build -t aspnet .
有了那个 Dockerfile,你就可以执行 docker build -t aspnet 了。 and then run it interactively by docker run -it aspnet.
然后通过 docker run -it aspnet 以交互方式运行它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.