Delay in catching docker exit code in bash script
Toying around with scheduling a bash script that spins up a docker container to see if windmill would flag a job as failed if the container exited with 1.
Inside the container is a py script that craps out with a sys.exit(1) in about half runs.
Unless I set a "sleep" in the bash script windmill considers the run successful regardless of how the docker container exits. Anyone know why that is?
containerid=$(docker run -d crashing-container:v1.0 python main.py -r)
#sleep 1
exitcode=$(docker inspect --format='{{.State.ExitCode}}' $containerid)
echo "Container exit code: " $exitcode
if [ $exitcode -eq 0 ]; then
echo "Container {$containerid} ExitCode:{$exitcode} - Yay!"
exit 0 #unless sleep, bash script always exits through here...
else
echo "Container {$containerid} ExitCode:{$exitcode} - Fail!"
exit 1
fi
2 Replies
That looks like a bug indeed
do you there there is a way to reproduce this with using exit codes and sleep to mimic the timings instead of using docker ?
If yes, could you file a github issue ?
using a bash script to execute a python script which randomly craps out using sys.exit(1) does not produce what I see with docker above.
Nevermind.. The docker metadata is obviously set AFTER the container is finished executing its main process and shut down.
Adding a sleep after docker run, or better yet using "docker wait "$containerid" is the trick