Last active
November 5, 2015 16:03
-
-
Save nowk/43338d7e47e9834da77f to your computer and use it in GitHub Desktop.
Basic command template around `docker run` to bootstrap some basic options
This file contains hidden or 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/sh | |
set -e | |
if [ ! -n "$1" ] ; then | |
echo | |
cat <<EOF | |
USAGE: | |
./docker-run <command> [-- <docker options>] | |
COMMANDS: | |
<command> Your command | |
OPTIONS: | |
-- <docker options> Options to be passed to the Docker \`run\` command | |
The --rm flag is automatically set as an option unless the --detach flag is true. | |
EOF | |
echo | |
return 0 | |
fi | |
image='image/name:version' # TODO set this to your image | |
rmflag=true | |
volume= # TODO set default volumes | |
cmd= | |
opt= | |
# build the command and break at -- | |
while [ "$#" -gt 0 ] ; do | |
case "$1" in | |
--) | |
shift | |
break | |
;; | |
*) | |
cmd="$cmd $1" | |
;; | |
esac | |
shift | |
done | |
# build docker options, everthing after -- | |
while [ "$#" -gt 0 ] ; do | |
case "$1" in | |
-d|--detach|--detach=true) | |
opt="$opt $1" | |
rmflag=false | |
;; | |
*) | |
opt="$opt $1" | |
;; | |
esac | |
shift | |
done | |
# check to see if we should ad the --rm flag to options | |
if [ "$rmflag" = true ] && [ "$CIRCLE_CI" != true ] ; then | |
opt="$opt --rm" | |
fi | |
exec /bin/sh -c "docker run ${volume} ${opt} -it ${image} ${cmd}" | |
# vim: filetype=sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment