Last active
September 7, 2015 17:20
-
-
Save rtfpessoa/697a379cd97ebf695a06 to your computer and use it in GitHub Desktop.
Docker run timeout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
DOCKER_TIMEOUT=$1 | |
shift | |
CONTAINER=$(docker run -d "$@") | |
docker stop --time=900 $CONTAINER | |
EXIT_CODE=$(docker wait $CONTAINER) | |
echo $(docker logs -f $CONTAINER) | |
docker rm -f $CONTAINER &> /dev/null | |
exit $EXIT_CODE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
DOCKER_TIMEOUT=$1 | |
shift | |
CONTAINER=$(docker run -d "$@") | |
UNAME=`uname` | |
if [[ "$UNAME" == 'Linux' ]]; then | |
EXIT_CODE=$(timeout "$DOCKER_TIMEOUT" docker wait "$CONTAINER" || echo 1) | |
elif [[ "$UNAME" == 'Darwin' ]]; then | |
EXIT_CODE=$(gtimeout "$DOCKER_TIMEOUT" docker wait "$CONTAINER" || echo 1) | |
fi | |
docker kill -f $CONTAINER &> /dev/null | |
echo $(docker logs $CONTAINER) | |
docker rm -f $CONTAINER &> /dev/null | |
exit $EXIT_CODE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment