Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Helpful aliases to interact with Docker
# ------------------------------------
# Docker Aliases
# ------------------------------------
# Get latest container ID
alias dl="docker ps -l -q"
# Get running containers
alias dps="docker ps"
# Get all containers
alias dpa="docker ps -a"
# Get images
alias di="docker images"
# Stop all running containers
dstop() { docker stop $(docker ps -q); }
# Remove container(s) (e.g. `drm containerA containerB`)
drm() { docker rm }
# Remove all containers
drma() { docker rm $(docker ps -a -q); }
# Stop and Remove all containers
alias drmf='docker stop $(docker ps -q) && docker rm $(docker ps -a -q)'
# Remove image(s) (e.g., `drmi imageA imageB`)
alias drmi="docker rmi"
# Remove all images
drmia() { docker rmi -f $(docker images -q); }
# Dockerfile build with specific tag. (e.g., `dbu tcnksm/test`)
dbu() { docker build -t=$1 .; }
# Show all alias related docker
dalias() { alias | grep 'docker' | sed "s/^\([^=]*\)=\(.*\)/\1 => \2/"| sed "s/['|\']//g" | sort; }
# Attach Container ("SSH into container")
dattach() { docker exec -i -t $1 bash }
# Follow Container Log ("tail -f" a container's output)
alias dfollow="docker logs --follow"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.