简体   繁体   English

Docker 容器挂在 exec 命令上

[英]Docker container hangs on exec command

Trying to execute shell commands in the docker container from localhost and inside the container,尝试从本地主机和容器内部在 docker 容器中执行 shell 命令,

  docker exec -i <container-id> sh -c "ls -l"

also tried docker exec -ti <container-id> sh -c "ls -l"还尝试docker exec -ti <container-id> sh -c "ls -l"

it lists the output and keeps on hanging in the terminal.它列出了输出并继续挂在终端上。

Executed the above command by login in to the container It lists the output and when i type exit command, it starts hanging通过登录到容器执行上述命令它列出了输出,当我键入exit命令时,它开始挂起

Server Free RAM: 3GB服务器可用内存:3GB

docker logs --details <container-id> 

returns empty output返回空输出

You need to allocate a pseudo-TTY with the -t option along with interactive or -i option. 您需要使用-t选项以及interactive或-i选项分配伪TTY。 Try this: 试试这个:

$ docker exec -ti <container-id> sh -c "ls -l"

Had the same issue.有同样的问题。 I was passing a step-by-step docker tutorial.我正在通过一个循序渐进的 docker 教程。 Was using Visual Studio 2022. In step-by-step tutorial worked fine.使用的是 Visual Studio 2022。在分步教程中效果很好。

When I tried myself docker exec command hanged.当我自己尝试 docker exec 命令时挂起。

The reason of the issue was that I used built in Visual Studio package manager console.问题的原因是我使用了内置的 Visual Studio 包管理器控制台。 But for running docker commands one should specifically start powershell console from the context menu of the solution.但是对于运行 docker 命令,应该从解决方案的上下文菜单中专门启动 powershell 控制台。

For details you can visit this link有关详细信息,您可以访问此链接

Kind of similar happened for me too.类似的事情也发生在我身上。 Was using Phpstorm terminal and it hanged.正在使用 Phpstorm 终端并挂起。 Restarted server - nothing.重新启动服务器 - 什么都没有。 Only complete reboot of phpstorm helped...只有完全重启 phpstorm 才有帮助...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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