简体   繁体   English

在正在运行的容器上执行“docker exec”时运行出错

[英]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 容器知之甚少,但我的猜测是shbashcat等 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.execmd.exe而不是使用shbashcat 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.

相关问题 所有正在运行的容器上的Docker exec - Docker exec on all running containers 在运行开发容器的同时运行Docker集成测试容器 - Running docker integration test containers while dev containers running 是否可以像执行到 docker 容器或在 pod 内运行的容器一样执行到 K8s pod? - Is it possible to exec in to a K8s pod the same way we exec in to a docker containers or containers running inside of a pod? Docker:删除正在运行的容器时出错 - Docker : error when delete running containers docker ps 正在运行容器 - docker ps is running the containers 按图像名称停止docker容器,如果没有容器正在运行,则不会出错 - Stopping docker containers by image name, and don't error if no containers are running 如何在 Windows 上运行 Linux 容器 - 运行时出错。\docker.exe pull ubuntu - How to run Linux containers on Windows - Error while running .\docker.exe pull ubuntu 运行私有docker映像时出错:standard_init_linux.go:207:exec用户进程导致“ exec格式错误” - Error while running private docker image : standard_init_linux.go:207: exec user process caused “exec format error” 在Docker中运行Jenkins时出错 - Error while running Jenkins in Docker 运行Docker容器时出错 - Error while running docker container
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM