Skip to content

Instantly share code, notes, and snippets.

@nickccm1122
Last active August 10, 2019 09:38
Show Gist options
  • Save nickccm1122/09dc99d853dbf02066addb2c0d7e5956 to your computer and use it in GitHub Desktop.
Save nickccm1122/09dc99d853dbf02066addb2c0d7e5956 to your computer and use it in GitHub Desktop.
my docker command functions or aliases
#!/usr/bin/sh
################################
# functions
################################
# docker contianer logs
dklog(){
docker ps -a \
--format "table{{.ID}}\t{{.Names}}\t{{.Ports}}" \
--filter="name=$1" \
| fzf \
| awk '{print $1}' \
| xargs docker logs --tail 100 -f
}
# show docker port
dkp(){
docker ps -a \
--format "table{{.ID}}\t{{.Names}}\t{{.Ports}}" \
| fzf \
| awk '{print $2}' \
| xargs docker port
}
################################
# widgets
################################
# docker contianer logs, pretty print
dklog-widget(){
eval dklog | pino-pretty -l
zle reset-prompt
}
zle -N dklog-widget
bindkey '^[dl' dklog-widget
# enter docker container
dkexec-witget(){
local cmd="docker ps -a --format \"table{{.ID}}\t{{.Names}}\t{{.Ports}}\" | fzf | awk '{print \$1}'"
RET_ID=$(eval "$cmd")
LBUFFER="docker exec -it $RET_ID bash"
zle reset-prompt
}
zle -N dkexec-witget
bindkey '^[de' dkexec-witget
# `docker ps` formated
alias dkps='docker ps -a --format "table{{.ID}} {{.Names}}\t{{.Command}}\t{{.Status}}\t{{.Image}}"'
# list inactive containers
alias dkpi='docker ps -a --format "table{{.ID}}\t{{.Names}}\t{{.Status}}\t{{.Command}}" -f "status=exited"'
# top-like `docker ps`
alias dktop='docker stats --format "table{{.Container}}\t{{.Name}}\t{{.CPUPerc}}\t{{.MemPerc}}\t{{.BlockIO}}"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment