如何确定 Docker exec 中的命令何时完成

huangapple go评论99阅读模式
英文:

How to determine when cmds in docker exec complete

问题

我目前正在使用Docker Rest API在容器上运行exec命令来开始构建一个Maven项目。我想知道Docker是否提供了一种方法来确定你附加到exec命令的命令何时完成,或者我是否需要开始寻找其他解决方案。

英文:

I'm currently using the Docker Rest API to run an exec command on a container to start building a maven project. I was wondering if there was any way provided by Docker to determine when the cmds you attach to the exec cmd complete or if I need to start getting creative

答案1

得分: 1

根据exec api spec,如果你没有将detach设置为true,那么一旦命令执行完成,Web Socket就会关闭。如果你从exec中分离(detach),那么你可以使用exec inspect api并轮询Running字段直到其变为false。

如果你正在使用exec api来运行一个交互式shell,并且将命令作为shell的输入而不关闭stdin,那么该shell将会挂起,就像在docker之外运行它一样。你可以关闭shell的stdin,或者如果这不是一个选项,你需要"有创意"地解决这个问题。

英文:

From the exec api spec if you do not set detach to true, the web socket should close once the command finishes. If you do detach from the the exec, then you can use the exec inspect api and poll for Running to go to false.

If you're using the exec api to run an interactive shell and you run your commands as input to the shell without closing stdin, then that shell will hang just as if you ran it outside of docker. You can close stdin to the shell or you'll need to "get creative" if that's not an option.

huangapple
  • 本文由 发表于 2017年1月31日 09:20:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/41948271.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定