简体   繁体   中英

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

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. Below is my docker file

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. 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 .

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. Instead you should invoke powershell.exe for example as described here:

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 . 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 . Here the solution and explanation of this problem is given
Solution : Changes in Dockerfile
Add ENTRYPOINT["powershell"]

FROM microsoft/aspnet
ENTRYPOINT["powershell"]
COPY ./bin/Release/PublishOutput .

Explanation:

The entrypoint is defined as 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. With that Dockerfile, you could then do docker build -t aspnet . and then run it interactively by docker run -it aspnet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM