-
-
Save e-belair/42c6c81c969b51be3f6f14a6ddfb6efb to your computer and use it in GitHub Desktop.
Useful Docker Aliases
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################################ | |
# # | |
# ------- Useful Docker Aliases -------- # | |
# # | |
# # Usage: # | |
# dc : docker-compose # | |
# dchelp : show this help # | |
# dcu : docker-compose up -d # | |
# dcd : docker-compose down # | |
# 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> # | |
# dsa : stop all containers # | |
# dsr <container>: stop then remove <container> # | |
# # | |
############################################################################ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################################ | |
# # | |
# ------- Useful Docker Aliases -------- # | |
# # | |
# # Usage: # | |
# dchelp # | |
############################################################################ | |
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 $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 | |
} | |
function dl-fn { | |
docker logs -f $1 | |
} | |
function drun-fn { | |
docker run -it $1 /bin/bash | |
} | |
function dsr-fn { | |
docker stop $1;docker rm $1 | |
} | |
function dsa-fn { | |
docker stop $(docker ps -a -q) | |
} | |
export DC_ALIAS_DIR="$(dirname $(readlink -f $0))" | |
alias dc="docker-compose" | |
alias dchelp="cat $DC_ALIAS_DIR/docker-aliases-help.txt" | |
alias dcu="docker-compose up -d" | |
alias dcd="docker-compose down" | |
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="docker rm $(docker ps --all -q -f status=exited)" | |
alias drmid="docker rmi $( docker images -q -f dangling=true)" | |
alias drun=drun-fn | |
alias dsa=dsa-fn | |
alias dsr=dsr-fn |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment