Skip to content

Instantly share code, notes, and snippets.

@tynes
Created May 17, 2018 22:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save tynes/29518fd1a06a467fb0ec6bda0e101e8a to your computer and use it in GitHub Desktop.
Save tynes/29518fd1a06a467fb0ec6bda0e101e8a 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