Skip to content

Instantly share code, notes, and snippets.

@tym-xqo
Last active August 29, 2015 14:24
Show Gist options
  • Save tym-xqo/cfc4e13328a444132745 to your computer and use it in GitHub Desktop.
Save tym-xqo/cfc4e13328a444132745 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Standard `docker exec -t` doesn't create a full tty, and has no $TERM set.
# This creates problems for me sometimes (I like the `clear` command, and
# psql complains a bit if the client is not a functional terminal).
# I do the command below enough that I made this script.
# Pass it the name or ID of a running container, and Bob's your uncle.
while true;
do
case $1 in
-e)
cid=$(docker ps | grep $2 | grep -v pause | cut -f 1 -d' ')
docker exec -it $cid script -f /dev/null -c "export TERM=xterm && /bin/bash"
break
;;
*)
cid=$(docker ps | grep $1 | grep -v pause | cut -f 1 -d' ')
echo $cid; break
;;
esac
done
@tym-xqo
Copy link
Author

tym-xqo commented Jul 2, 2015

So, I put a symlink to this in my $PATH, and then I can go exectty postgres or whatever and I'm in with a more functional terminal than bare exec /bin/bash gives you, and I don't even have to look up the container ID.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment