4 # Get a login for a docker container.
14 dssh: log in to a docker node
16 usage: dssh: [options]
19 -h: show this help message.
20 -i [ID]: ssh into a docker node with this container ID
21 -n [name]: ssh into a docker node with this name
22 -t [0 or 1]: 0 to avoid allocating a TTY; 1 to allocate one.
23 The default will be set based on whether this appears
24 to be an interactive shell.
35 while getopts "hi:n:t:" flag; do
38 i) DOCKER_IMAGE_ID=${OPTARG};;
39 n) DOCKER_IMAGE_NAME=${OPTARG};;
40 t) ALLOCATE_TTY=${OPTARG};;
41 *) echo "getopts error"
47 shift $(expr $OPTIND - 1)
49 RUN_COMMAND="/bin/bash"
54 which docker &>/dev/null || die "docker must be on the PATH."
56 if [ "x${DOCKER_IMAGE_NAME}" == "x" ]; then
57 if [ "x${DOCKER_IMAGE_ID}" == "x" ]; then
62 if [ "x${DOCKER_IMAGE_ID}" == "x" ]; then
65 echo "You must not supply both an ID and a name."
68 DOCKER_IMAGE_ID=$(docker ps -f name=${DOCKER_IMAGE_NAME} -q)
69 [ "x${DOCKER_IMAGE_ID}" == "x" ] && \
70 die "failed to find a docker image named ${DOCKER_IMAGE_NAME}"
73 if [ ${ALLOCATE_TTY} == 1 ]; then
74 docker exec -it "${DOCKER_IMAGE_ID}" "${@}" ${RUN_COMMAND}
76 docker exec -i "${DOCKER_IMAGE_ID}" "${@}" ${RUN_COMMAND} &