-
-
Save yashodhank/0717c1068b395e773fd12536da4c0af8 to your computer and use it in GitHub Desktop.
docker exec bash alias
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
# usage: | |
# dexec <cmd> | |
# uses fzf to select running container then runs | |
# $ docker run [selected] <cmd> | |
# with /bin/bash as the default cmd | |
# TODO: add some pretty printing | |
function dexec() { | |
local selected_image | |
selected_image=$(docker ps --format='NAME: {{.Names}}, ID: {{.ID}}, IMAGE: {{.Image}}, COMMAND: {{.Command}}, PORTS: {{.Ports}}' | fzf) | |
local id | |
id=$(echo "$selected_image" | cut -f2 -d ',' | cut -f2 -d ':' | tr -d ' ') | |
local cmd | |
local dcmd=${1:-/bin/bash} | |
cmd="docker exec -it ${id} ${dcmd}" | |
echo "running: ${cmd}" | |
eval "$cmd" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment