Skip to content

Instantly share code, notes, and snippets.

@Quicksync
Forked from jgrodziski/docker-aliases.sh
Created November 1, 2024 09:52
Show Gist options
  • Save Quicksync/16f0a78b7dcbf12bf36f44bfaae6f65b to your computer and use it in GitHub Desktop.
Save Quicksync/16f0a78b7dcbf12bf36f44bfaae6f65b to your computer and use it in GitHub Desktop.
Useful Docker Aliases
############################################################################
# #
# ------- Useful Docker Aliases -------- #
# #
# # Installation : #
# copy/paste these lines into your .bashrc or .zshrc file #
# #
# # Usage: #
# #
# dex <container>: execute a bash shell inside the running <container> #
# di <container> : docker inspect <container> #
# dim : docker images #
# dipall : IP addresses of all running containers #
# dnames : names of all running containers #
# dps : docker ps #
# dpsa : docker ps -a #
# #
############################################################################
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 dipall-fn {
echo "IP addresses of all named running containers"
for DOC in `dnames-fn`
do
IP=`docker inspect $DOC | grep -m3 IPAddress | cut -d '"' -f 4 | tr -d "\n"`
echo $DOC : $IP
done
}
function dex-fn {
docker exec -it $1 /bin/bash
}
function di-fn {
docker inspect $1
}
alias dex=dex-fn
alias di=di-fn
alias dim="docker images"
alias dipall=dipall-fn
alias dnames=dnames-fn
alias dps="docker ps"
alias dpsa="docker ps -a"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment