badsequelB
Windmill2y ago
5 replies
badsequel

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
Was this page helpful?