Advertisement
4tolexx

docker aliases

Feb 22nd, 2023
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. # functions for docker commands aliases
  2. function dnames-fn {
  3. for ID in `docker ps | awk '{print $1}' | grep -v 'CONTAINER'`
  4. do
  5. docker inspect $ID | grep Name | head -1 | awk '{print $2}' | sed 's/,//g' | sed 's%/%%g' | sed 's/"//g'
  6. done
  7. }
  8.  
  9. function dip-fn {
  10. echo "IP addresses of all named running containers"
  11.  
  12. for DOC in `dnames-fn`
  13. do
  14. IP=`docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}} {{end}}' "$DOC"`
  15. OUT+=$DOC'\t'$IP'\n'
  16. done
  17. echo -e $OUT | column -t
  18. unset OUT
  19. }
  20.  
  21. function dex-fn {
  22. docker exec -it $1 ${2:-bash}
  23. }
  24.  
  25. function di-fn {
  26. docker inspect $1
  27. }
  28.  
  29. function dl-fn {
  30. docker logs -f $1
  31. }
  32.  
  33. function drun-fn {
  34. docker run -it $1 $2
  35. }
  36.  
  37. function dcr-fn {
  38. docker-compose run $@
  39. }
  40.  
  41. function dsr-fn {
  42. docker stop $1;docker rm $1
  43. }
  44.  
  45. function drmc-fn {
  46. docker rm $(docker ps --all -q -f status=exited)
  47. }
  48.  
  49. function drmid-fn {
  50. imgs=$(docker images -q -f dangling=true)
  51. [ ! -z "$imgs" ] && docker rmi "$imgs" || echo "no dangling images."
  52. }
  53.  
  54. # in order to do things like dex $(dlab label) sh
  55. function dlab {
  56. docker ps --filter="label=$1" --format="{{.ID}}"
  57. }
  58.  
  59. function dc-fn {
  60. docker-compose $*
  61. }
  62.  
  63. function d-aws-cli-fn {
  64. docker run \
  65. -e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \
  66. -e AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION \
  67. -e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \
  68. amazon/aws-cli:latest $1 $2 $3
  69. }
  70.  
  71. alias daws=d-aws-cli-fn
  72. alias dc=dc-fn
  73. alias dcu="docker-compose up -d"
  74. alias dcd="docker-compose down"
  75. alias dcr=dcr-fn
  76. alias dex=dex-fn
  77. alias di=di-fn
  78. alias dim="docker images"
  79. alias dip=dip-fn
  80. alias dl=dl-fn
  81. alias dnames=dnames-fn
  82. alias dps="docker ps"
  83. alias dpsa="docker ps -a"
  84. alias drmc=drmc-fn
  85. alias drmid=drmid-fn
  86. alias drun=drun-fn
  87. alias dsp="docker system prune --all"
  88.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement