Skip to content

Instantly share code, notes, and snippets.

@calbertts
Last active November 4, 2019 14:29
Show Gist options
  • Save calbertts/8ce6727d782112fd74e5ef32fbc260e4 to your computer and use it in GitHub Desktop.
Save calbertts/8ce6727d782112fd74e5ef32fbc260e4 to your computer and use it in GitHub Desktop.
Runs a command in a running docker container
runinc() {
export FZF_DEFAULT_OPTS='--height 90% --reverse --border'
local container=$(docker ps --format '{{.Names}} => {{.Image}}' | fzf-tmux --reverse --multi | awk -F '\\=>' '{print $1}')
if [[ $container != '' ]]; then
echo -e "\n \033[1mDocker container:\033[0m" $container
read -e -p $' \e[1mOptions: \e[0m' -i "-it" options
if [[ $@ == '' ]]; then
read -e -p $' \e[1mCommand: \e[0m' cmd
else
cmd="$@"
fi
echo ''
history -s runinc "$@"
history -s docker exec $options $container $cmd
docker exec $options $container $cmd
echo ''
fi
export FZF_DEFAULT_OPTS=""
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment