Skip to content

Instantly share code, notes, and snippets.

@outro56
Created August 25, 2020 01:55
Show Gist options
  • Save outro56/f8b60a59ff0aea521d3435767bf20f49 to your computer and use it in GitHub Desktop.
Save outro56/f8b60a59ff0aea521d3435767bf20f49 to your computer and use it in GitHub Desktop.
run docker contains with default arguments
dockerx() {
if [ "$#" -eq "0" ]; then
echo "Usage: dockerx IMAGE [OPTIONS]"
return 1
else
img=$1
shift
# remove invalid characters from the container name
name=`echo "$img" | tr /:?\ @ _`
cmd="docker run -it --rm --name $name -v $PWD:/workdir -w /workdir $img $@"
echo $cmd
eval $cmd
fi
}
export -f dockerx >/dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment