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
I want to continue script execution only if nginx config test is success, not when fail.
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).
I found this to be working quite well:
Translating my comment into an answer. This should work:
It works for me.
The
api/client/exec.go#L97-L100
does get the exit code:That comes from
api/client/utils.go#L84-L97
So if your command fail, you will get the exit code.
Although, as mentioned here, you could use
nginx -t
instead ofconfigtest
.