Skip to content

Instantly share code, notes, and snippets.

@legeiger
Last active June 7, 2024 09:07
Show Gist options
  • Save legeiger/fc4a70780aeea3bc7bef33abeed0adb4 to your computer and use it in GitHub Desktop.
Save legeiger/fc4a70780aeea3bc7bef33abeed0adb4 to your computer and use it in GitHub Desktop.
aliases for use with bash. save to $HOME
alias diffs='diff --side-by-side --suppress-common-lines'
# docker compose
alias dc='docker compose'
alias dcbu='docker compose up --build -d'
alias dcu='docker compose up -d'
alias dcd='docker compose down'
alias dcl='docker compose logs -f'
alias dcps='docker compose ps'
alias dcpu='docker compose pull && docker-compose up -d'
alias dbash='docker exec -it'
# list files
alias ll='ls -lh --color=auto'
alias ll='ls -l'
alias la='ls -a'
alias llh='ls -lh'
alias lt='ls --human-readable --size -S --classify'
function trash() { mv "$@" ~/.Trash; }
function dbash() { docker exec -it "$@" bash; }
# include .docker-aliases if it exists
if [ -f $HOME/.docker-aliases.sh ]; then
. $HOME/.docker-aliases.sh
fi
if [ -f $HOME/.tmux-aliases.sh ]; then
. $HOME/.tmux-aliases.sh
fi
alias vidinfo="ffprobe -v quiet -print_format json -show_format -show_streams -print_format json"
############################################################################
# #
# ------- Useful Docker Aliases -------- #
# #
# # Installation : #
# copy/paste these lines into your .bashrc or .zshrc file or just #
# type the following in your current shell to try it out: #
# wget -O - https://gist.githubusercontent.com/jgrodziski/9ed4a17709baad10dbcd4530b60dfcbb/raw/d84ef1741c59e7ab07fb055a70df1830584c6c18/docker-aliases.sh | bash
# #
# # Usage: #
# daws <svc> <cmd> <opts> : aws cli in docker with <svc> <cmd> <opts> #
# dc : docker-compose #
# dcu : docker-compose up -d #
# dcd : docker-compose down #
# dcr : docker-compose run #
# dex <container>: execute a bash shell inside the RUNNING <container> #
# di <container> : docker inspect <container> #
# dim : docker images #
# dip : IP addresses of all running containers #
# dl <container> : docker logs -f <container> #
# dnames : names of all running containers #
# dps : docker ps #
# dpsa : docker ps -a #
# drmc : remove all exited containers #
# drmid : remove all dangling images #
# drun <image> : execute a bash shell in NEW container from <image> #
# dsr <container>: stop then remove <container> #
# #
############################################################################
function dnames-fn {
for ID in `docker ps | awk '{print $1}' | grep -v 'CONTAINER'`
do
docker inspect $ID | grep Name | head -1 | awk '{print $2}' | sed 's/,//g' | sed 's%/%%g' | sed 's/"//g'
done
}
function dip-fn {
echo "IP addresses of all named running containers"
for DOC in `dnames-fn`
do
IP=`docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}} {{end}}' "$DOC"`
OUT+=$DOC'\t'$IP'\n'
done
echo -e $OUT | column -t
unset OUT
}
function dex-fn {
docker exec -it $1 ${2:-bash}
}
function di-fn {
docker inspect $1
}
function dl-fn {
docker logs -f $1
}
function drun-fn {
docker run -it $1 $2
}
function dcr-fn {
docker-compose run $@
}
function dsr-fn {
docker stop $1;docker rm $1
}
function drmc-fn {
docker rm $(docker ps --all -q -f status=exited)
}
function drmid-fn {
imgs=$(docker images -q -f dangling=true)
[ ! -z "$imgs" ] && docker rmi "$imgs" || echo "no dangling images."
}
# in order to do things like dex $(dlab label) sh
function dlab {
docker ps --filter="label=$1" --format="{{.ID}}"
}
function dc-fn {
docker-compose $*
}
function d-aws-cli-fn {
docker run \
-e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \
-e AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION \
-e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \
amazon/aws-cli:latest $1 $2 $3
}
function dtop-fn {
docker stats --format "table {{.Container}}\t{{.Name}}\t{{.CPUPerc}} {{.MemPerc}}\t{{.NetIO}}\t{{.BlockIO}}"
}
function dstats-fn {
docker stats --no-stream;
}
alias daws=d-aws-cli-fn
alias dc=dc-fn
alias dcu="docker-compose up -d"
alias dcd="docker-compose down"
alias dcr=dcr-fn
alias dex=dex-fn
alias di=di-fn
alias dim="docker images"
alias dip=dip-fn
alias dl=dl-fn
alias dnames=dnames-fn
alias dps="docker ps"
alias dpsa="docker ps -a"
alias drmc=drmc-fn
alias drmid=drmid-fn
alias drun=drun-fn
alias dsp="docker system --all"
alias dsr=dsr-fn
alias dtop=dtop-fn
alias dstats=dstats-fn
alias dsa="docker stop $(docker ps -a -q)"
alias dser="docker service"
alias dvol="docker volume ls"
alias dm="docker-machine"
alias dmx="docker-machine ssh"
# Some tmux-related shell aliases
# Attaches tmux to the last session; creates a new session if none exists.
alias t='tmux attach || tmux new-session'
# Attaches tmux to a session (example: ta portal)
alias ta='tmux attach -t'
# Creates a new session
alias tn='tmux new-session'
# Lists all ongoing sessions
alias tls='tmux list-sessions'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment