commit de6c8ebde01294c16eec080b247818bb1d9745e8
parent 5920813d8bcdcf5d9f16a729e6829fc72c4e12a1
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Mon, 3 Dec 2018 14:56:49 +0100
Add docker-shell for starting an interactive shell in a docker image
Diffstat:
1 file changed, 41 insertions(+), 0 deletions(-)
diff --git a/links/bin/docker-shell b/links/bin/docker-shell
@@ -0,0 +1,41 @@
+#!/usr/bin/env bash
+set -e
+
+function help {
+ echo "Usage: ${0##*/} IMAGE [SHELL]"
+ echo "where IMAGE is a valid Docker image, or one of the predefined"
+ echo "shortcuts (e.g., alpine, ubuntu, ubuntu-lts), and the optional"
+ echo "argument SHELL sets the shell to run in the image."
+}
+
+case "$1" in
+ ubuntu-lts)
+ img="ubuntu:16.04"
+ [ ! -z "$2" ] && shell="$2" || shell="bash"
+ ;;
+ alpine)
+ img="alpine"
+ [ ! -z "$2" ] && shell="$2" || shell="sh"
+ ;;
+ -h)
+ help
+ exit 0
+ ;;
+ --help)
+ help
+ exit 0
+ ;;
+ *)
+ img="$1"
+ [ -z "$2" ] && shell="$2" || shell="bash"
+ ;;
+esac
+
+
+if [ "$(uname)" = "Linux" ]; then
+ dockercmd="sudo docker"
+else
+ dockercmd="docker"
+fi
+
+eval "$dockercmd" run -i -t "$img" "$shell"