docker exec命令的结果 [英] The result of docker exec command
本文介绍了docker exec命令的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在我的shell脚本中知道一些docker exec命令的输出,例如,我有一个nginx容器,并且在我的脚本中运行:
I need to know in my shell script the output of some docker exec commands, for example I have an nginx container and in my script I run:
docker exec -it containerName /etc/init.d/nginx configtest
我只想在nginx配置下继续执行脚本测试是成功,而不是失败。
I want to continue script execution only if nginx config test is success, not when fail.
我尝试使用 $?
,但这是 0
即使configtest输出也会失败(因为据我所知,因为docker exec已成功执行)。
I've tried out to use $?
, but it is 0
even then configtest output is fail (because docker exec is successfully executed, as I understand).
推荐答案
我发现这效果很好:
docker exec -t -i my-container sh -c 'my-command; exit $?'
这篇关于docker exec命令的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文