Last active
February 3, 2019 17:50
-
-
Save cowgill/6f1e163f19347734c6c0b8a59b160817 to your computer and use it in GitHub Desktop.
Alias and function list for Docker commands.
This file contains 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
# Put these in ~/.bash_profile and save | |
# Then source the file to activate them | |
# source ~/.bash_profile | |
# | |
# Credit for original list | |
# https://github.com/tcnksm/docker-alias/blob/master/zshrc | |
# Get process included stop container | |
alias dps="docker ps -a" | |
# Remove all stopped containers | |
alias dpsp="docker container prune -f" | |
# Get images | |
alias di="docker images" | |
# Remove all dangling images | |
alias dip="docker image prune -f" | |
# Execute interactive container, e.g., $dex base /bin/bash | |
alias dex="docker exec -i -t" | |
# Start dev instance | |
alias dcu="docker-compose up" | |
# Stop dev instance | |
alias dcd="docker-compose down" | |
# Start prod instance | |
alias dcuprod="docker-compose -f docker-compose.yml up" | |
# Build dev images | |
alias dcb="docker-compose build" | |
# Build prod images | |
alias dbprod="docker-compose -f docker-compose.yml build" | |
################ | |
# Functions | |
# Usage without params: FUNCTION_NAME | |
# Usage with params: FUNCTION_NAME <IMAGE_NAME> | |
# e.g. dbu my-docker-image | |
################ | |
# Stop all containers | |
dstop() { docker stop $(docker ps -a -q); } | |
# Remove all containers | |
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 | |
dri() { docker rmi $(docker images -q); } | |
# Dockerfile build, e.g., $dbu tcnksm/test | |
dbu() { docker build -t=$1 .; } | |
# Show all alias related docker | |
dalias() { alias | grep -E 'docker|docker-compose' | sed "s/^\([^=]*\)=\(.*\)/\1 => \2/"| sed "s/['|\']//g" | sort; } | |
# Bash into running container | |
dbash() { docker exec -it $(docker ps -aqf "name=$1") bash; } | |
# Show image history and space used by each item | |
# Usage: $ dih <IMAGE_NAME> | |
dih() { docker image history -H “$1”; } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment