dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles # fast
git clone https://src.adamsgaard.dk/dotfiles.git # slow
Log | Files | Refs | README | LICENSE Back to index

docker-shell (712B)


      1 #!/bin/sh
      2 set -e
      3 
      4 help() {
      5 	echo "Usage: ${0##*/} IMAGE [SHELL]"
      6 	echo "where IMAGE is a valid Docker image, or one of the predefined"
      7 	echo "shortcuts (e.g., alpine, ubuntu, ubuntu-lts), and the optional"
      8 	echo "argument SHELL sets the shell to run in the image."
      9 }
     10 
     11 [ $# -lt 1 ] && (help && exit 1)
     12 case "$1" in
     13 	ubuntu-lts)
     14 		img="ubuntu:18.04"
     15 		[ -n "$2" ] && shell="$2" || shell="bash"
     16 		;;
     17 	alpine)
     18 		img="alpine"
     19 		[ -n "$2" ] && shell="$2" || shell="sh"
     20 		;;
     21 	-h|--help)
     22 		help
     23 		exit 0
     24 		;;
     25 	*)
     26 		img="$1"
     27 		[ -z "$2" ] && shell="$2" || shell="bash"
     28 		;;
     29 esac
     30         
     31 
     32 if [ "$(uname)" = "Linux" ]; then
     33 	dockercmd="sudo docker"
     34 else
     35 	dockercmd="docker"
     36 fi
     37 
     38 eval "$dockercmd" run -i -t "$img" "$shell"