Last active
December 8, 2017 12:28
-
-
Save calbertts/28a722928fa0346e70769602d518e75c to your computer and use it in GitHub Desktop.
Runs a docker container from an image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
runc() { | |
export FZF_DEFAULT_OPTS='--height 90% --reverse --border' | |
local image=$(docker images --format '{{.Repository}}:{{.Tag}}' | fzf-tmux --reverse --multi) | |
if [[ $image != '' ]]; then | |
echo -e "\n \033[1mDocker image:\033[0m" $image | |
read -e -p $' \e[1mOptions: \e[0m' -i "-it --rm" options | |
printf " \033[1mChoose the command: \033[0m" | |
local cmd=$(echo -e "/bin/bash\nsh" | fzf-tmux --reverse --multi) | |
if [[ $cmd == '' ]]; then | |
read -e -p $' \e[1mCustom command: \e[0m' cmd | |
fi | |
echo -e " \033[1mCommand: \033[0m" $cmd | |
export FZF_DEFAULT_COMMAND='find ./ -type d -maxdepth 1 -exec basename {} \;' | |
printf " \033[1mChoose the volume: \033[0m" | |
local volume=$(fzf-tmux --reverse --multi) | |
local curDir=${PWD##*/} | |
if [[ $volume == '.' ]]; then | |
echo -e " \033[1mVolume: \033[0m" $volume | |
volume="`pwd`:/$curDir -w /$curDir" | |
else | |
echo -e " \033[1mVolume: \033[0m" $volume | |
volume="`pwd`/$volume:/$volume -w /$volume" | |
fi | |
export FZF_DEFAULT_COMMAND="" | |
export FZF_DEFAULT_OPTS="" | |
history -s runc | |
history -s docker run $options -v $volume $image $cmd | |
echo '' | |
docker run $options -v $volume $image $cmd | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment