This content originally appeared on DEV Community and was authored by Rubin
Docker has been there for a long time and its my top most used tool whether for spinning up a web server or trying out a new tool.
If you are like me and use docker on your day to day dev workflow, these aliases would help you save few keystrokes for common use cases and save your time.
You can set up in your shell configuration file (like .bashrc, .zshrc, etc.):
Get latest container ID
alias dl="docker ps -l -q"
Get container process
alias dps="docker ps"
Get process included stop container
alias dpa="docker ps -a"
Get images
alias di="docker images"
Get container IP
alias dip="docker inspect --format '{{ .NetworkSettings.IPAddress }}'"
Run daemonized container, e.g., $dkd base /bin/echo hello
alias dkd="docker run -d -P"
Run interactive container, e.g., $dki base /bin/bash
alias dki="docker run -i -t -P"
Execute interactive container, e.g., $dex base /bin/bash
alias dex="docker exec -i -t"
Stop all containers
alias dstop='docker stop $(docker ps -a -q)'
Remove all containers
alias drm='docker rm $(docker ps -a -q)'
Stop and Remove all containers
alias drmf='docker stop $(docker ps -a -q) && docker rm $(docker ps -a -q)'
Remove all images
alias dri='docker rmi $(docker images -q)'
Dockerfile build, e.g., $dbu tcnksm/test
alias dbu='docker build -t=$1 .'
Show all alias related docker
dalias() { alias | grep 'docker' | sed "s/^\([^=]*\)=\(.*\)/\1 => \2/" | sed "s/['|\']//g" | sort; }
Bash into running container
alias dbash='docker exec -it $(docker ps -aqf "name=$1") bash'
This content originally appeared on DEV Community and was authored by Rubin

Rubin | Sciencx (2024-06-30T17:20:11+00:00) Useful aliases for docker. Retrieved from https://www.scien.cx/2024/06/30/useful-aliases-for-docker/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.