Skip to content

Instantly share code, notes, and snippets.

@yashodhank
Forked from tynes/dexec.sh
Created May 28, 2020 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yashodhank/0717c1068b395e773fd12536da4c0af8 to your computer and use it in GitHub Desktop.
Save yashodhank/0717c1068b395e773fd12536da4c0af8 to your computer and use it in GitHub Desktop.
docker exec bash alias
# 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