-h: show this help message.
-i [ID]: ssh into a docker node with this container ID
-n [name]: ssh into a docker node with this name
+-t [0 or 1]: 0 to avoid allocating a TTY; 1 to allocate one.
+ The default will be set based on whether this appears
+ to be an interactive shell.
EOF
}
DOCKER_IMAGE_ID=""
DOCKER_IMAGE_NAME=""
-while getopts "hi:n:" flag; do
+if [ -t 0 ]; then
+ ALLOCATE_TTY=1
+else
+ ALLOCATE_TTY=0
+fi
+while getopts "hi:n:t:" flag; do
case $flag in
h) usage; exit 0;;
i) DOCKER_IMAGE_ID=${OPTARG};;
n) DOCKER_IMAGE_NAME=${OPTARG};;
+ t) ALLOCATE_TTY=${OPTARG};;
*) echo "getopts error"
echo
usage
else
RUN_COMMAND="${@}"
fi
+EXTRA_DOCKER_ARGS=""
+if [ ${ALLOCATE_TTY} -ne 0 ]; then
+ EXTRA_DOCKER_ARGS="${EXTRA_DOCKER_ARGS} -t"
+fi
which docker &>/dev/null || die "docker must be on the PATH."
die "failed to find a docker image named ${DOCKER_IMAGE_NAME}"
fi
-docker exec -it "${DOCKER_IMAGE_ID}" ${RUN_COMMAND}
+docker exec -i ${EXTRA_DOCKER_ARGS} "${DOCKER_IMAGE_ID}" ${RUN_COMMAND}